Install MySQL under Ubuntu 18.04

Time:2021-6-13

Tip: the following operations are performed under the root permission.

#To check whether MySQL is installed:

dpkg -l | grep mysql

#To install MySQL:

apt install mysql-server

After the installation, you can use the following command to check whether the installation is successful:

netstat -tap | grep mysql

After the above command check, if you see that the socket of MySQL is in the listen state, it means that the installation is successful.

You can log in to MySQL database through the following command:

mysql -u root -p

-U is the user name to log in, and – P is the user password to log in. Now, there is no password in the MySQL database. Enter password: to enter the MySQL database.

Then through show databases; You can view all the current databases.

Next, in order to ensure the security and normal operation of the database, initialize the database. This initialization involves the following five steps.

(1) Install the password verification plug-in.

(2) Set the exclusive password of the root administrator in the database.

(3) Then delete the anonymous account and use the root administrator to remotely log in to the database to ensure the security of the business running on the database.

(4) Delete the default test database and cancel a series of access rights of the test database.

(5) Refresh the authorization list to make the initialization settings take effect immediately.

For the above operation steps of database initialization, I made a simple comment next to the output information below.

[email protected]ubuntu-virtual-machine:~# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? # Do you want to install the password verification plug-in?

Press y|y for yes, any other key for No: n
Please set the password for root here.

New password: # enter the database password to be set for the root administrator

Re enter new password: # re enter the password

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? ( Press y | y for yes, any other key for no): y # delete anonymous account
Success.

Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? ( Press y | y for yes, any other key for no): n # forbid the root administrator to log in remotely, but I don’t forbid it here

… skipping.
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? ( Press y | y for yes, any other key for no): y # delete the test database and cancel access to it
– Dropping test database…
Success.

– Removing privileges on test database…
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? ( Press y | y for yes, any other key for no): y # refresh the authorization table to make the initialization settings take effect immediately
Success.

All done!

Check the MySQL service status:

systemctl status mysql

The following results show that the MySQL service is running normally:

Again, use the command MySQL – U root – P, enter password: and press enter to enter the MySQL database.

Using use MySQL; Command to open the database named by MySQL and display the tables of the current database: show tables; Query the data in the user table: select * from user( The user table contains all the account information of MySQL database.)

Now configure Mysql to allow remote access. Edit it first/etc/mysql/mysql.conf.d/mysqld.cnf Profile:

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Comment it outbind-address = 127.0.0.1

Save and exit, then enter MySQL database and execute the authorization command:

mysql -u root -p
MySQL > grant all on *. * to root @ '%' identified by 'your password' with grant option;
mysql> flush privileges; #  Refresh permissions
mysql> exit

Then execute the exit command to exit the MySQL service, and then execute the following command to restart MySQL:

systemctl restartmysql

Now under windows, you can use Navicat graphical tools to connect to MySQL database under Ubuntu remotely, and enter the password of the remote permission just authorized.

By the way, let’s share the Navicat for MySQL 10.1.7 installation package

Link: https://pan.baidu.com/s/12P1BcvQsRetBY0jGIvwILw&shfl=shareset Extraction code: 8bft

OK, so far, the installation of MySQL under Ubuntu 18.04 has been completed.

During the operation, I encountered the following errors:

E: Unable to get lock / var / lib / dpkg / lock front – Open (11: resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

For the solution, refer to the article: https://www.jb51.net/article/172460.htm

summary

The above is the way to install MySQL under Ubuntu 18.04 introduced by Xiaobian. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply you in time. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!