Binary deploy MySQL 5.7

Binary deploy simple, no need to install depend on the environment, can go to the official website mysql download MySQL binary packages. Or through a link to my network disk download , dish network has links script automatically deployed.

Note: The latest version of MySQL 8.0 and 5.7 versions of the deployment process exactly the same, just binary package file just not the same.

1. Uninstall mariadb

[root@mysql01 ~]# yum -y erase mariadb
[root@mysql01 ~]# rpm -e qt-mysql-4.8.7-2.el7.x86_64 --nodeps

2, deployment mysql 5.7

[root@mysql01 src]# tar zxf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz 
[root@mysql01 src]# mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql
[root@mysql01 src]#  ln -sf /usr/local/mysql/bin/* /usr/local/bin/

3, edit the configuration file and initialize the MySQL

[root@mysql01 src]# rm -rf /etc/my.cnf
[root@mysql01 src]# vim /etc/my.cnf      #编辑MySQL主配置文件
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
log-error=/usr/local/mysql/data/mysql.err
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
#创建所需目录及用户并更改属主
[root@mysql01 src]#  mkdir /usr/local/mysql/data
[root@mysql01 src]# useradd -M -s /sbin/nologin mysql
[root@mysql01 src]# chown -R mysql.mysql /usr/local/mysql/
#初始化MySQL
[root@mysql01 src]# mysqld --initialize --user mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
#添加为系统服务
[root@mysql01 src]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql01 src]# chkconfig --add mysqld
#启动并设置为开机自启
[root@mysql01 src]# systemctl enable mysqld
[root@mysql01 src]# systemctl start mysqld
#确定3306端口在监听
[root@mysql01 src]# netstat -anpt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      2589/mysqld         

4, modify the initial MySQL root user password

#获取root用户的初始密码
[root@mysql01 src]# mysqlpwd=`cat /usr/local/mysql/data/mysql.err | grep password |awk -F'root@localhost: ' '{print $2}'`
#重置密码为123.com
[root@mysql01 src]# mysql -uroot -p${mysqlpwd} -e 'alter user root@localhost identified by "123.com"' --connect-expired-password
#使用新密码进行登录测试
[root@mysql01 src]# mysql -uroot -p123.com
#附加:MySQL中的help命令使用
mysql> help show;          #此命令可以查看出所有show命令使用语法,可以help+任意命令字

-------- end of this article so far, thanks for reading --------

Guess you like

Origin blog.51cto.com/14154700/2457416