ubuntu 18.04安装mysql

1、首先要更新源,执行apt update命令,如下图所示:

ubuntu 18.04安装mysql_第1张图片

2、执行apt install mysql-server命令,然后输入Y即可安装,如下图所示:

ubuntu 18.04安装mysql_第2张图片

3、安装好之后就开始配置,直接输入: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
Please set the password for root here.

New password: 

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) : N

 ... skipping.


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) : Y
Success.

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) : N

 ... skipping.
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! 

如下图所示:

ubuntu 18.04安装mysql_第3张图片

4、配置远程访问,首先编辑配置文件,通过:vim /etc/mysql/mysql.conf.d/mysqld.cnf命令进行编辑,将bind-address           = 127.0.0.1注释掉,如下图所示:

ubuntu 18.04安装mysql_第4张图片

5、输入mysql -uroot -p命令进入mysql中,如下图所示:

ubuntu 18.04安装mysql_第5张图片

6、然后输入:grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;表示允许任何主机远程连接,连接的密码是123456,如下图所示:

ubuntu 18.04安装mysql_第6张图片

7、exit退出,然后重启mysql服务:service mysql restart,如下图所示:

8、然后在另外一台机进行测试,如下图所示:

ubuntu 18.04安装mysql_第7张图片

ubuntu 18.04安装mysql_第8张图片

你可能感兴趣的:(ubuntu 18.04安装mysql)