MySql is an open source database management system. It provides with tables and fields for storing necessary information.
Before we start, let us make sure that the Underlying Ubuntu Server is updated with its latest update. Run the below command on the server.
Now, once the Ubuntu server is up and running with the latest updates, now its time to install MySQL on Linux.
apt install mysql-server
You need to agree to use the space by pressing “Y”
You may ignore that by pressing “Enter” Or you may set the Mysql root user password in this screen. We can do that later anyway.
I think, if you ignore this during installation, the splash screen will come 3 times to input a password.
Now, run the below command to secure your MySQL database.
This will come up with few questions and that would expect you to Press “Y/n”
It’s up to each individual, based on your need, you can proceed with the right selection.
Let me put all the questions here So that you know what are they.
Question 1: This will ask if you want to Set Root Password for your MySQL database.
I have selected “n” so it skipped.
Question 2: This will ask if you want to remove the anonymous user.
Question 3: Disable remote root login.
Remaining Questions are below.
Now, your MySQL is installed on Ubuntu. To verify that execute the below command.
Run the command (1) mysql
You will get a blinking line with (2) mysql>
Few basic Queries:
1. To list all the databases.
mysql> show databases;
2. To use any database from above.
mysql> use mysql; ( use database_name)
3. To see the list of tables
mysql> show tables;
4. List the fields of any table, I use these two ways. There could be others, please comment and let me know.
mysql> describe user;
mysql> select * from user limit 1;
You can see, the user “root” does not have any password.
Now, To set a password for the root user you can use the below command.
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass’; ( I think this is for the latest versions )
To check if the user got any password, you can execute the below command.
mysql> select user,password,host,
authentication_string from user where user='root';
Now, from next time, when you log in to the SQL server locally.
Most importantly you have to use the below command to log in
MySQL -u root -p;