ENV:
[root@lnmp ~]# uname -r
3.10.0-514.el7.x86_64
[root@lnmp ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
安装过程:
一:上传或下载mysql5.7.30的glib安装包
下载地址:https://dev.mysql.com/downloads/mysql/
我下载的是完整包
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar
[root@lnmp ~]# cd Downloads/
[root@lnmp Downloads]# ls
[root@lnmp Downloads]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz...
100% 644548 KB 14648 KB/sec 00:00:44 0 Errors
Transferring mysql.sh...
100% 530 bytes 530 bytes/sec 00:00:01 0 Errors
[root@lnmp Downloads]# ls
mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz mysql.sh
二:编写mysql.sh直接使用安装脚本安装,使过程更简单
/usr/lib/systemd/system/mysqld.service 这个文件是systemctl命令所需文件,很多的文章中并没有写这一类的,我只是采用自己电脑上的文件直接套用的,效果还不错,因有英文注解,这里不解释。
mysql的安装目录为/usr/local/mysql data目录为 /usr/local/mysql/data 用户 mysql
mysql的安装设置可参考mysql官方文档进行设置,我这里只是简单操作过程。不要照搬!!!
bin/mysqld --initialize --datadir=/usr/local/mysql/data --user=mysql --basedir=/usr/local/mysql
[root@lnmp Downloads]# vim mysql.sh
###############mysql.sh##############
#!/bin/bash
tar -zxf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql
useradd -r -s /sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql
cd /usr/local/mysql
yum remove mariadb-libs -y
mkdir data
bin/mysqld --initialize --datadir=/usr/local/mysql/data --user=mysql --basedir=/usr/local/mysql
cat <<-EOF >>/usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables
#ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd
# Start main service
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
# Use this to switch malloc implementation
#EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
# Set enviroment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
EOF
systemctl start mysqld.service
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
#############mysql.sh##################
三:执行安装过程
[root@lnmp Downloads]# source mysql.sh
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00
extras/7/x86_64 | 2.9 kB 00:00
updates/7/x86_64 | 2.9 kB 00:00
updates/7/x86_64/primary_db | 3.0 MB 00:08
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
mariadb-libs x86_64 1:5.5.52-1.el7 @anaconda 4.4 M
Removing for dependencies:
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M
Transaction Summary
================================================================================
Remove 1 Package (+1 Dependent package)
Installed size: 17 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2
Erasing : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2
Verifying : 2:postfix-2.10.1-6.el7.x86_64 1/2
Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2
Removed:
mariadb-libs.x86_64 1:5.5.52-1.el7
Dependency Removed:
postfix.x86_64 2:2.10.1-6.el7
Complete!
2020-07-02T09:19:05.170535Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-02T09:19:08.076657Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-02T09:19:08.525940Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-02T09:19:08.689979Z 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: 1573d557-bc45-11ea-a95f-525400846a22.
2020-07-02T09:19:08.718856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-02T09:19:09.347700Z 0 [Warning] CA certificate ca.pem is self signed.
2020-07-02T09:19:09.565705Z 1 [Note] A temporary password is generated for root@localhost: 5AwE3Amu?;3T
这里最后mysql安装完后会给出mysql的密码。要注意
四:查看启动状态并使用
如需要加入开机启动列表 systemctl enable mysqld 实现开机启动
[root@lnmp mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2020-07-02 18:39:44 CST; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 6824 (mysqld)
CGroup: /system.slice/mysqld.service
└─6824 /usr/local/mysql/bin/mysqld
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.418628Z 0 [Note] Ski...y.
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.419292Z 0 [Note] Ser...06
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.419345Z 0 [Note] IPv...e.
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.419360Z 0 [Note] -...';
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.419387Z 0 [Note] Ser...'.
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.429885Z 0 [Note] Inn...ol
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.431224Z 0 [Note] Inn...45
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.474817Z 0 [Note] Eve...ts
Jul 02 18:39:45 lnmp mysqld[6824]: 2020-07-02T10:39:45.475714Z 0 [Note] /us...s.
Jul 02 18:39:45 lnmp mysqld[6824]: Version: '5.7.30' socket: '/tmp/mysql.s...L)
Hint: Some lines were ellipsized, use -l to show in full.
[root@lnmp mysql]# source /etc/profile
[root@lnmp mysql]# mysql -uroot -p"5AwE3Amu?;3T"
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 6
Server version: 5.7.30
Copyright (c) 2000, 2020, 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> exit
Bye
五:修改密码并使用mysql
mysql5.7之后的版本的安全考虑,第一次进入后需重新设置密码才能进行正常操作,修改一个新的密码吧。
[root@lnmp Downloads]# mysql -uroot -p"5AwE3Amu?;3T"
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.30
Copyright (c) 2000, 2020, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user user() identified by 'Mysql5.7';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye