Installing MySQL under Ubuntu18.04

Note: The following operations are carried out by the root authority.

# See if there install MySQL:

dpkg -l | grep mysql

# Install MySQL:

apt install mysql-server

14733211-6197c3897ccc6c0d.png

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

netstat -tap | grep mysql

After inspection by the above command, you see if the mysql socket in the LISTEN state indicates a successful installation.

14733211-ec7f95f1daabbe42.png

Log mysql database via the following command:

mysql -u root -p

-u user name indicating the selection of landing, -p represents a user password, now is the mysql database without a password, Enter password: directly at Enter, you can enter the mysql database.

Then show databases; you can view all current database.

14733211-d438a26f05c07a7b.png

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

(1) installation verification password plugin.

(2) Set the root proprietary database administrator password.

(3) subsequently removed anonymous account and log in as root from a remote database administrator to ensure the safety of the operation on the database business.

(4) delete the default test database, canceled a series of test access to the database.

(5) to refresh the authorization list, let initialization settings take effect immediately.

For database initialization procedure described above, the next output below I made a simple comment.

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:# 输入要为root管理员设置的数据库密码

Re-enter new 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 # 禁止root管理员从远程登录,这里我没有禁止

... 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  # 删除test数据库并取消对它的访问权限

- 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  # 刷新授权表,让初始化后的设定立即生效

Success.

All done!

14733211-3dd53fe3cca5518b.png

检查mysql服务状态:

systemctl status mysql

显示如下结果说明mysql服务运行是正常的:

14733211-c9ff9d6bb3aae140.png

再次用mysql -u root -p命令,Enter password:处输入刚设置的密码,回车,就能够进入mysql数据库。

Use use mysql; command to open the database named mysql, display the current table in the database: show tables; user query data table: select * from user; (user account information table is all mysql database)

14733211-700a7dc8c90bcc95.png

Mysql is now configured to allow remote access, first edit /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

14733211-008f3c7c8a90a01a.png

Save and exit, and then enter the mysql database, perform authorization command:

mysql -u root -p

. Mysql> grant all on * * to root @ '%' identified by 'your password' with grant option;

mysql> flush privileges; # refresh permission

mysql> exit

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

systemctl restart mysql

Reproduced in: https: //www.jianshu.com/p/b54ed11f021f

Guess you like

Origin blog.csdn.net/weixin_34301132/article/details/91323436
Recommended