ubuntu20.10下mysql8数据库的安装(亲测)

1、安装

$ sudo apt update

$ sudo apt install mysql-server

2、配置mysql

$ sudo mysql_secure_installation

首先便是要求设置root用户的密码:

在成功设置root密码之后还会有一系列的一些安全设置:

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) : y
 - 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!

3、验证mysql的安装:

$ systemctl status mysql.service

4、使用root命令和刚才设置的密码来登陆到 mysql中去

1,登进MySQL之后,
$ sudo mysql -uroot –p
2,输入以下语句,进入mysql库:
use mysql
3,更新域属性,'%'表示允许外部访问:
update user set host='%' where user ='root';
4,执行以上语句之后再执行:
FLUSH PRIVILEGES;
5,再执行授权语句:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;

报错:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_secure_installation
update user set host='localhost' where user ='root'' at line 1

执行sql:

select user,host,password  from mysql.user;

执行sql:

ALTER USER 'root'@'localhost' IDENTIFIED BY '_huitao';

刷新

FLUSH PRIVILEGES;

修改参数:

注意到8.0 5.7多了带“.”的变量导致只设置一半是不够的

set global validate_password.policy=0;
set global validate_password.length=4;

然后退出后再执行

mysql_secure_installation

update user set plugin="mysql_native_password",authentication_string=password('设置的密码') where user="root";

刷新权限
FLUSH PRIVILEGES;

 

navica连接不上数据库解决办法:

1,用如下语句查看MySQL当前加密方式

select host,user,plugin from user;

看第一行,root加密方式为caching_sha2_password。

2,使用命令将他修改成mysql_native_password加密模式:

update user set plugin='mysql_native_password' where user='root';

navica连接数据库:

 

 

猜你喜欢

转载自blog.csdn.net/chehec2010/article/details/115214676