How to create mysql database in Linux
MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language. In this post, I’m going to guide you on how to create a mysql database in Linux.
Note: You can get “ERROR 1698 (28000): Access denied for user ‘root’@’localhost’ in MySQL” error, while you are trying to login mysql server. I wrote an article about this error, you can view it here.
- Login mysql server
mysql -u root -p - Create a database
create database dbname; - Create a user and set permission for this user
create user ‘username’@’localhost’ identified by ‘password’;
grant all on dbname.* to username@localhost;
Note: You can allow this user to some specific permissions. To do this, you can use the below command:
grant SELECT on dbname.* to username@localhost; // SELECT is a permission
The list permissions on mysql are:
ALLALTER
CREATE VIEW
CREATE
DELETE
DROP
GRANT OPTION
INDEX
INSERT
SELECT
SHOW VIEW
TRIGGER
UPDATE
- [Option] Change password for this user
set password for ‘username’@’localhost’ = password(‘new_password’); - Reload all the privileges
FLUSH PRIVILEGES; - Exit mysql server
exit;