Share This

Tuesday, October 13, 2009

Creating a MySQL Database from Command Line

It seems easy but a bit dizzy one for a novice, so let me share a simple guide.
If you don't have MySql installed, you can download it from
http://dev.mysql.com/downloads/,
one should also read the documentation here http://dev.mysql.com/doc/.
During installation, you will have to configure the server instance, optionally the port number (default is 3306) and the root password.
After the installation, you may want to check the MySQL CLI. Assuming System Environment Variable has been given and you can now access its commands.
The syntax is simply as below,
$ mysql -u ''username'' -p
It will prompt for root password or it can be given as below
$ mysql -u ''username'' -p"password"
Where "username" is the name of any accounts created during the setup or an additional one with specific privileges. Also note that no space is between -p and your password if it's given. To create new user, here's a simple guide
https://www.digitalocean.com/community/articles/how-to-create-a-new-user-and-grant-permissions-in-mysql
Well, this is all you need to create a new database.
mysql> CREATE DATABASE ''databasename'';
If you want to grant a user to your database, issue this command,
mysql> GRANT ALL PRIVILEGES ON ''databasename''.* TO "''username''"@"''hostname''" IDENTIFIED BY "''password''";
mysql> FLUSH PRIVILEGES;
You have to flush the privileges in order to activate it. Finally, if you want to exit,
mysql> EXIT

No comments:

Post a Comment