How To Create MySQL database with SSH command in Php.?

Creating a MySQL database via SSH:-   First of all you need to have the server root access to begin creating database using the SSH command line. Then follow the steps to create database using the SSH command line.

Here are the steps to create the Database and user by using the SSH Command.

  • Step 1-: Begin by opening your terminal and connect to the server by using the syntax below:
    ssh username@hostname

  • Step 2:- After successful login to the server and now login for the mysql using the command below:
    mysql -u root -p
  • -u is the user and -p stands for password to complete the login for mysql.

  • Step 3:- After Successfully login now use the following command to create the database in your server.
    CREATE DATABASE your_database;

  • If a database with same name exits than it will receive error for which you can do the following command to create new database.

  • Step4:- By default there are the privileges set to the database for the root user. In case you want to provide the access to the different user, you can do with the following commands.
    GRANT USAGE ON database_name.* to new_user@localhost 
    IDENTIFIED BY 'user_passwd';

  • Step 5:- To Give all privileges to the new user then use the following command line for giving full authority to the new user respectively.
    GRANT ALL ON your_database.* to user@localhost;

  • Step 6:-Now flush the current privileges to take the effect of the new user privileges use the below command to get this done with immediate effect.
    flush privileges;

  • Step 7:-Now new user can login and access the database with the full given authority for making changes effectively.
    mysql -u new_user -p 'user_passwd' your_database

  • Step 8. You can now exit your server by typing:

  • To View All Your Created Database:-
  • To view the all the database you have created in server simply use the following command:
    mysql> SHOW DATABASES;
    | Database           |
    | information_schema |
    | your_database      |

  • How to Select Your Database?

    To select a database use the following command:-

    USE your_db_name;

    Hope this will be helpful, Thanks and Enjoy the PHP Coding.

    You may also like...

    Leave a Reply

    Your email address will not be published. Required fields are marked *