Install mysql5.0+ on Ubuntu 18.04

Tips: The following operations are all performed under the root user, if you are an ordinary user, please add sudo by yourself!

Check whether MySQL is installed:

dpkg -l | grep mysql

Install MySQL:

After apt install mysql-server is
Insert picture description here
installed, you can use the following command to check whether the installation is successful:

netstat -tap | grep mysql

After checking through the above command, if you see that the mysql socket is in the LISTEN state, the installation is successful.
Insert picture description here
You can log in to the mysql database through the following command:

mysql -u root -p

-u means the user name to choose to log in, -p means the password of the user who logs in, now there is no password in the mysql database, and press Enter directly at Enter password: to enter the mysql database.

Then through show databases; you can view all current databases.

Insert picture description here
Next, in order to ensure the security and normal operation of the database, the database is initialized. This initialization operation involves the following 5 steps.

(1) Install the verification password plug-in.

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

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

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

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

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

root@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? # 要安装验证密码插件吗?

Press y|Y for Yes, any other key for No: N # 这里我选择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 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 # 删除匿名账户
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 root administrator to log in remotely, here I did not prohibit

… 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 test database and 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 initialized settings take effect immediately
. Success.

All done!

Insert picture description here
Check the mysql service status:

systemctl status mysql

The following results show that the mysql service is running normally:
Insert picture description here
use the mysql -u root -p command again, enter the password you just set at Enter password: and press Enter to enter the mysql database.

Use the 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 the mysql database)
Insert picture description here
Now configure mysql to allow remote access , First edit the /etc/mysql/mysql.conf.d/mysqld.cnf configuration file:

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

Comment out bind-address = 127.0.0.1,
Insert picture description here
save and exit, then enter the 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 privileges

mysql> exit

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

systemctl restart mysql

Now under Windows, you can use Navicat graphical tools to remotely connect to the MySQL database under Ubuntu, and enter the password for the newly authorized remote permissions.
OK, the installation of MySQL under Ubuntu 18.04 has been completed.

Guess you like

Origin blog.csdn.net/Fengfgg/article/details/113555833