mysql 5.7 二进制普通安装

1 官网下载mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
2 可以先检查系统中的Mysql或mariadb,如果存在将其卸载
[ ~]# rpm -qa |grep mysql
php-mysql-5.4.16-46.1.el7_7.x86_64
[ ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
mariadb-server-5.5.64-1.el7.x86_64
mariadb-5.5.64-1.el7.x86_64
[ ~]# yum -y remove php-mysql-5.4.16-46.1.el7_7.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.x86_64 0:5.4.16-46.1.el7_7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size

3 useradd -M -s /sbin/nologin -r mysql  //-M不创建主目录,-s /sbin/nologin不允许登录,-r创建的是系统用户
4 tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/  //解压
cd /usr/local/
mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql
cd mysql
mkdir data  //创建数据目录
chown -R mysql.mysql /usr/local/mysql/
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

//显示第一次登录的随机密码 注意这里的秘密

[ mysql]# vi /etc/my.cnf

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql/mysql.sock
[client]
socket=/usr/local/mysql/mysql.sock
环境变量的配置
[ mysql]# vi /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[ mysql]# source /etc/profile.d/mysql.sh
cp support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
chmod +x /etc/init.d/mysqld
[ mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[ mysql]#
mysql
mysql -uroot -p‘e>;Yl?WVp7Na‘

mysql> set password for =password(‘123456‘);

相关推荐