//安装依赖包和下载二进制mysql包
[root@server ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@server ~]# groupadd -r -g 306 mysql
[root@server ~]# useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql
[root@server ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
//解压配置mysql
[root@server ~]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@server ~]# cd /usr/local/
[root@server local]# ls
apache apr-util etc include lib64 mysql-5.7.22-linux-glibc2.12-x86_64 share
apr bin games lib libexec sbin src
[root@server local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.22-linux-glibc2.12-x86_64/"
[root@server local]# ls
apache apr-util etc include lib64 mysql sbin src
apr bin games lib libexec mysql-5.7.22-linux-glibc2.12-x86_64 share
[root@server local]# chown -R mysql.mysql /usr/local/mysql
[root@server local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 12月 19 10:59 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
[root@server local]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[root@server local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@server local]# . /etc/profile.d/mysql.sh
[root@server local]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server local]# mkdir /opt/data
[root@server local]# chown -R mysql.mysql /opt/data/
[root@server local]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 12月 19 11:00 data
//初始化数据库
[root@server ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/2019-12-19T03:01:35.862161Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-19T03:01:36.673480Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-19T03:01:36.882420Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-19T03:01:37.307046Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: df361822-220b-11ea-ba15-000c296e029d.
2019-12-19T03:01:37.308394Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-19T03:01:37.309741Z 1 [Note] A temporary password is generated for root@localhost: qK(iyJrAB4SP
[root@server ~]# echo 'qK(iyJrAB4SP' > pass
[root@server ~]# cat pass
qK(iyJrAB4SP
//配置mysql
[root@server ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@server ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@server ~]# ldconfig
[root@server ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
//启动mysql
[root@server ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@server ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@server ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
[root@server ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/server.err'.
SUCCESS!
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:57330 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::49181 :::*
LISTEN 0 80 :::3306 :::*
//修改mysql密码
[root@server ~]# cat pass
qK(iyJrAB4SP
[root@server ~]# mysql -uroot -p'qK(iyJrAB4SP'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('wangqing123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye