本文转载,向高手致敬!
1、安装YUM Repo
由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件。
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
然后进行repo的安装:
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo mysql-community-source.repo
2、安装MySQL
使用yum命令即可完成安装
yum install mysql-server
启动msyql:
systemctl start mysqld #启动MySQL
配置MySQL
获取安装时的临时密码:
grep 'temporary password' /var/log/mysqld.log
登录:
mysql -u root -p
划重点:如果中途报错:can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
1.删除原来安装过的mysql残留的数据(这一步非常重要,问题就出在这)
rm -rf /var/lib/mysql
2.重启mysqld服务
systemctl restart mysqld
3.再去找临时密码
grep 'temporary password' /var/log/mysqld.log
登录成功后修改密码:
set password=password("yourpassword");
设置安全选项:
mysql_secure_installation
其他设置:
systemctl stop mysqld #关闭MySQL
systemctl restart mysqld #重启MySQL
systemctl status mysqld #查看MySQL运行状态
systemctl enable mysqld #设置开机启动
systemctl disable mysqld #关闭开机启动
请执行