mysql5.7下载地址 mysql8.0下载地址
挂载iso镜像,并安装以依赖包;mysql-community-server依赖net-tools、perf,若已经安装过vim,可不用额外安装perf。(vim依赖perf)
mkdir /media/CentOS mount -t iso9660 -o ro,loop /opt/CentOS-7-x86_64-DVD-1810.iso /media/CentOS ls /media/CentOS yum --disablerepo=\* --enablerepo=c7-media install -y net-tools perf安装MySQL
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 rpm -ivh ./mysql-community-common-5.7.31-1.el6.x86_64.rpm rpm -ivh ./mysql-community-libs-5.7.31-1.el6.x86_64.rpm rpm -ivh ./mysql-community-client-5.7.31-1.el6.x86_64.rpm rpm -ivh ./mysql-community-server-5.7.31-1.el6.x86_64.rpm开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload关闭SeLinux
setenforce 0 getenforce vi /etc/selinux/config # enforcing修改为disabled SELINUX=disabledmysql登录时报socket找不到终极解决方案
注意: 若已经初始化过MySQL之后,需要复制原始数据目录到新的数据目录,然后启动MySQL服务。
cd /home/data/mysql cp -pr /var/lib/mysql/* .首次启动MySQL时,会对MySQL进行初始化。所以,请尽量一次性的配置好/etc/my.cnf文件。避免额外的工作步骤。
#查看自动生成的临时密码 cat /var/log/mysqld.log |grep password 查询结果如下: 2020-09-03T07:51:34.045157Z 1 [Note] A temporary password is generated for root@localhost: ZuoOejf5Vj#d #登录 mysql -uroot -p'ZuoOejf5Vj#d' mysql> grant all privileges on *.* to 'root'@'localhost' identified by '123456' with grant option; mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; mysql> flush privileges;MySQL8.0创建用户的操作已经不支持grant的同时创建用户的方式,需先创建用户再进行授权。
修改密码: mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; 修改密码并指定加密方式: mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; mysql> flush privileges; 创建用户: mysql> create user 'root'@'%' identified by '123456'; mysql> grant all on *.* to 'root'@'%' WITH GRANT OPTION;; mysql> flush privileges;