Create MySQL database under Linux
If you want to create a MySQL database under Linux, you are often required to read long documentation. We have put together a compact guide on how to create a table and create a separate user for it.
Change the password from the MySQL database admin root
If you have freshly installed the database software, you must assign a password to your administrator account.
- To set your password, use the command: # mysqladmin -u root password YOURPASSWORD
- Tip: If you have installed the Plesk admin panel on your server, you no longer need to set a password. You can therefore skip this and the next step and simply log in with: # mysql -uadmin -p $ (cat /etc/psa/.psa.shadow)
How to log in to MySQL on Linux
You now pass your user name to the database program in one command. You will then be automatically asked to enter your password.
- # mysql -u root -p
Create your MySQL database
After you have logged in, you will now see the "mysql>" prompt at the beginning of the line: You can now use program-specific commands. First create your database using "create database".
- mysql> create database DATABASE NAME;
- Tip: If a database of the same name already exists, an error message is issued. You can avoid this with the modified command "create database if not exists DATENBANKNAME".
View all MySQL databases
If you manage several data collections, you may want to check in advance whether names have already been assigned or check whether your new database has been created. The "show databases" command lists the complete database.
- mysql> show databases;
Create a database user in MySQL on Linux
So that your database can also be used, you should create your own database user. Since MySQL does not automatically assign permissions, you must then grant your user access to the new database.
- mysql> create user 'USERNAME' @ 'localhost' identified by 'USER PASSWORD';
- mysql> grant all on DATABASE NAME. * to 'USERNAME' @ 'localhost';
- Tip: You can also combine both commands:
- mysql> grant all on DATABASE NAME. * to 'USERNAME' @ 'localhost' identified by 'USER PASSWORD';
These instructions have been tested with "mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2". We will show you how to create a database with OpenOffice Base in another guide.