ubuntu20.04 安装 mysql8.0.27

工作 / 2021-12-18

ubuntu20.04 安装 mysql8.0.27

#只检查不更新Ubuntu
sudo apt update     

Ubuntu 中apt update和upgrade 的区别

#下载安装mysql最新服务
sudo apt install mysql-server
#进行初始化配置
sudo mysql_secure_installation 
Securing the MySQL server deployment. 
 
Connecting to MySQL using a blank password. 
 
VALIDATE PASSWORD COMPONENT 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 component? 
 
Press y|Y for Yes, any other key for No: y


保护MySQL服务器部署。  
 
使用空白密码连接到MySQL。  
 
VALIDATE PASSWORD COMPONENT可用于测试密码  
和提高安全性。 它检查密码的强度  
并允许用户只设置那些密码  
足够安全。 要设置VALIDATE PASSWORD组件吗?  
 
按y| y表示是,其他任何键表示否:y  
There are three levels of password validation policy: 
 
LOW    Length >= 8 
MEDIUM Length >= 8, numeric, mixed case, and special characters 
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file 
 
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 

密码验证策略有三种级别:  
 
低长度>= 8  
MEDIUM长度>= 8,数字,大小写混合和特殊字符  
长度>= 8,数字,混合大小写,特殊字符和字典文件  
 
请输入0 = LOW, 1 = MEDIUM和2 = STRONG: 0  

# 需要输入密码
Please set the password for root here.

New password: 

Re-enter new password: 

请在这里设置root用户的密码。  
 
新密码:  
重新输入新密码:   
Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

估计密码的强度:50  
您希望继续使用所提供的密码吗? (按y| y表示是,任何其他键表示否):y  
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.


默认情况下,MySQL安装有一个匿名用户,  
允许任何人无需登陆MySQL  
为他们创建的用户帐户。 这只是为了  
测试,并使安装更顺利。  
您应该在进入产品之前删除它们  
环境。  

删除匿名用户? (按y| y表示是,任何其他键表示否):y  
成功。 
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

通常,根应该只允许连接  
“localhost”。 这就保证了别人猜不到  
从网络获取的根密码。  
 
禁止根用户远程登录? (按y| y表示是,其他键表示否):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.

...  跳过。  
重新加载特权表将确保所有更改  
目前所做的将立即生效。  
 
现在重新加载特权表? (按y| y表示是,任何其他键表示否):y  
成功。  
查看mysql版本
mysql --version 
查看MySQL运行状态
systemctl status mysql.service
进行连接
sudo mysql -u root -p
#打开文件修改bind-address=0.0.0.0
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
重启MySQL服务
sudo systemctl restart mysql.service
再次连接
查看密码强度
把密码强度修改成为 LOW 
sudo mysql -u root -p

SHOW VARIABLES LIKE 'validate_password%';
set global validate_password.policy=LOW; 
 创建远程连接账户并授权

 use mysql;
 CREATE USER 'root'@'%' IDENTIFIED BY 'Movies123.';
 grant all privileges on *.* to 'root'@'%';
 本地代码链接,改密码方式:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Movies123.';
 刷新权限

mysql> FLUSH PRIVILEGES;

数据库创建字符选择