ubuntu20.04安装mysql8.0

1.通过apt 安装MySQL

#命令1
sudo apt-get update
#命令2
sudo apt-get install mysql-server

ubuntu20.04安装mysql8.0_第1张图片

2. 配置MySQL

2.1 配置初始化信息

sudo mysql_secure_installation

配置说明:

weison@ubuntu19-04:~$ sudo 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: 

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(选择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) : N(选择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) : N(选择N,不删除test数据库)

 ... 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(选择Y,修改权限立即生效)
Success.

All done! 

2.2 配置访问权限

在Ubuntu下MySQL缺省是只允许本地访问的,使用workbench连接工具是连不上的;
如果你要其他机器也能够访问的话,需要进行配置;

2.2.1 配置远程访问

# 登陆mysql
sudo mysql -uroot -p
#切换数据库
use mysql;
#查询用户表命令:
select User,authentication_string,Host from user;

ubuntu20.04安装mysql8.0_第2张图片

访问权限说明:host默认都是localhost访问权限

 

localhost 本地连接
% 本地+远程连接
use mysql;

update user set host='%' where user='root';

#刷新cache中配置
flush privileges;  

1. 编辑mysql配置文件,把其中bind-address = 127.0.0.1注释了

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

 

2. 重启mysql

/etc/init.d/mysql restart
或
sudo service mysql restart

3.修改mysql密码

ALTER USER 'root'@'%' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY 'root';

//root为密码

 

你可能感兴趣的:(#,linux)