安装MySQL

阅读量: 2101 编辑

安装MySQL

在CentOS Linux上安装MySQL

一、下载并安装MySQL

#创建mysql目录
cd /root
mkdir mysql && cd mysql

#下载软件
wget \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-client-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-common-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-server-5.7.32-1.el7.x86_64.rpm

#执行安装
yum install -y mysql-community-*-5.7.32-1.el7.x86_64.rpm

二、开启MySQL服务器

systemctl start mysqld 
systemctl enable mysqld 

三、 查看默认生成的密码

cat /var/log/mysqld.log | grep password

四、连接MySQL

mysql -uroot -h127.0.0.1 -p

五、设置密码长度和等级

mysql> set global validate_password_length=10;
mysql> set global validate_password_policy=0;

六、修改默认密码,注意替换后面的密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '您的密码';