User login

MySQL database and user creation from the command line

Searched words: 
command line creating a mysql database mysql command line make new user database bash shell Unix Linux mysql create database grant all privileges mysql mariadb

On Agaric's test server, i need to log into MySQL as root to do these grant commands.

/usr/local/mysql/bin/mysql -uroot -p

On Debian, simply

mysql -uroot -p

worked. You have to put in your root password, of course. (And the lack of a space between -u and root is not a typo.)

In here, you can:

SHOW DATABASES;

CREATE DATABASE example_database;

GRANT ALL ON example_database.*
TO example_user@localhost IDENTIFIED BY 'p4ssw0rd';

Credit:
http://www.vbulletin.com/docs/html/main/cli_database

And quit gets you out of there.

Related:
http://agaricdesign.com/backing-up-restoring-making-test-databases-with-mysql-command-line

A note about database names with dashes

It helps so much to use the correct commands. Dashed database names can be quoted with backticks (`), but be careful to include only the database and not the table wildcard when granting privileges.

If MySQL gives a "No database selected" error on a GRANT statement, that is a clue that something is wrong.

mysql> GRANT ALL PRIVILEGES ON `drupal-sdl-test.*` TO 'sdl';
ERROR 1046 (3D000): No database selected

mysql> GRANT ALL PRIVILEGES ON `drupal-sdl-test`.* TO 'sdl';
Query OK, 0 rows affected (0.14 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.