Thu. Dec 12th, 2019

How to create mysql database in Linux

1 min read

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.

  1. Login mysql server
    mysql -u root -p
  2. Create a database
    create database dbname;
  3. 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:
    ALL

    ALTER

    CREATE VIEW

    CREATE

    DELETE

    DROP

    GRANT OPTION

    INDEX

    INSERT

    SELECT

    SHOW VIEW

    TRIGGER

    UPDATE

  4. [Option] Change password for this user
    set password for ‘username’@’localhost’ = password(‘new_password’);
  5. Reload all the privileges
    FLUSH PRIVILEGES;
  6. Exit mysql server
    exit;