生產環境可用mysql5.7.23安裝全過程
阿新 • • 發佈:2019-04-26
5.7 connect 修改 127.0.0.1 sys 需要 sshd files recv 生產環境安裝5.7.23全過程
先執行initialization.sh優化腳本 詳情見 Linux
在安裝mysql前,需要先查看一下是否清空了系統自帶了mysql
我們這裏需要刪除系統自帶了mysql lib
我們先把mysql放置在/opt下
先上傳與線上版本一致的
[[email protected] opt]# ll total 629320 -rw-r--r-- 1 root root 7214 Mar 27 17:37 initialization.sh -rw-r--r-- 1 root root 644399365 Oct 13 2018 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz drwxr-xr-x. 2 root root 4096 Nov 22 2013 rh drwxr-xr-x 2 root root 4096 Apr 23 16:34 scripts
第一步:刪除過期系統自帶的lib
[[email protected] opt]# rpm -qa|grep mysql mysql-libs-5.1.71-1.el6.x86_64 [[email protected] opt]# find / -name "mysql" /usr/share/mysql /usr/lib64/mysql [[email protected] opt]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64 [[email protected] opt]# rpm -qa|grep mysql [[email protected] opt]# find / -name "mysql"
第二步創建mysql的用戶
[[email protected] opt]# groupadd mysql
[[email protected] opt]# useradd -r -g mysql -s /bin/false mysql
第三步創建mysql的數據目錄[[email protected] opt]# mkdir -p /ivargo/data/mysql
第三步:解壓 mysql安裝包到/usr/local 下
[[email protected] opt]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ ... ... ... [[email protected] opt]# cd /usr/local/ [[email protected] local]# ll total 44 drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc drwxr-xr-x. 2 root root 4096 Sep 23 2011 games drwxr-xr-x. 2 root root 4096 Sep 23 2011 include drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64 drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec drwxr-xr-x 9 root root 4096 Apr 23 17:12 mysql-5.7.23-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin drwxr-xr-x. 5 root root 4096 Apr 16 2018 share drwxr-xr-x. 2 root root 4096 Sep 23 2011 src 到這來有2個方式,方式是 //一個是直接mv 一個是用ln -s 軟連接 在這裏我們實現和生產上一樣的,用mv
第四步:創建/usr/local/mysql
[[email protected] local]# mkdir mysql
[[email protected] local]# ll
total 48
drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
drwxr-xr-x 2 root root 4096 Apr 23 17:20 mysql
drwxr-xr-x 9 root root 4096 Apr 23 17:12 mysql-5.7.23-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 16 2018 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
[[email protected] local]# mv /usr/local/mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql
[[email protected] local]# rm -rf mysql-5.7.23-linux-glibc2.12-x86_64/
[[email protected] local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
drwxr-xr-x 9 root root 4096 Apr 23 17:21 mysql
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 16 2018 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
第五步:設置/usr/local/mysql 的權限
[[email protected] local]# pwd
/usr/local
[[email protected] local]# chown -R mysql:mysql mysql
第六步:修改mysql 配置文件
[[email protected] local]# pwd
/usr/local
[[email protected] local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
drwxr-xr-x 9 mysql mysql 4096 Apr 23 17:21 mysql
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 16 2018 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
[[email protected] local]# cd mysql/
[[email protected] mysql]# ll
total 52
drwxr-xr-x 2 mysql mysql 4096 Apr 23 17:12 bin
-rw-r--r-- 1 mysql mysql 17987 Jun 8 2018 COPYING
drwxr-xr-x 2 mysql mysql 4096 Apr 23 17:13 docs
drwxr-xr-x 3 mysql mysql 4096 Apr 23 17:11 include
drwxr-xr-x 5 mysql mysql 4096 Apr 23 17:12 lib
drwxr-xr-x 4 mysql mysql 4096 Apr 23 17:12 man
-rw-r--r-- 1 mysql mysql 2478 Jun 8 2018 README
drwxr-xr-x 28 mysql mysql 4096 Apr 23 17:12 share
drwxr-xr-x 2 mysql mysql 4096 Apr 23 17:12 support-files
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# ll
total 24
-rw-r--r-- 1 mysql mysql 773 Jun 8 2018 magic
-rwxr-xr-x 1 mysql mysql 1061 Jun 8 2018 mysqld_multi.server
-rwxr-xr-x 1 mysql mysql 894 Jun 8 2018 mysql-log-rotate
-rwxr-xr-x 1 mysql mysql 10576 Jun 8 2018 mysql.server
[[email protected] support-files]# cp mysql.server /etc/init.d/mysql
然後修改/etc/init.d/mysql的參數,
vim /etc/init.d/mysql
修改
basedir=/usr/local/mysql
datadir=/ivargo/data/mysql
設置mysql啟動的配置文件my.cnf 設置配置文件/etc/my.cnf
[[email protected] support-files]# find / -name "my.cnf"
[[email protected] opt]# mv my.cnf /etc/
[[email protected] opt]# ls -l /etc/my.cnf
-rw-r--r-- 1 root root 1649 Oct 11 2018 /etc/my.cnf
第七步:初始化mysql
[[email protected] bin]# pwd
/usr/local/mysql/bin
初始化命令
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql
[[email protected] bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql
...
...
...
第八步 :啟動mysql 並設置 開機自啟動 chkconfig mysql on
[[email protected] bin]# service mysql start
Starting MySQL.. SUCCESS!
[[email protected] bin]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1531/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1607/master
tcp 0 0 :::22 :::* LISTEN 1531/sshd
tcp 0 0 ::1:25 :::* LISTEN 1607/master
tcp 0 0 :::3306 :::* LISTEN 4567/mysqld
第九步 :重新設置mysql密碼
[[email protected] bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23-log
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.
@(none)> SET PASSWORD FOR ‘root‘@‘localhost‘=PASSWORD(‘xxx‘);
Query OK, 0 rows affected, 1 warning (0.01 sec)
@(none)> flush privileges;
Query OK, 0 rows affected (0.00 sec)
第十步:設置mysql的環境變量
我這裏用的 自己的方法
echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile
tail -1 /etc/profile
source /etc/profile
[[email protected] opt]# which mysql
/usr/local/mysql/bin/mysql
第十一步:優化mysql
@(none)> select user,host from mysql.user; //沒有優化前
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
[[email protected] opt]# find / -name "mysql_secure_installation"
/usr/local/mysql/bin/mysql_secure_installation
執行初始化命令之後,
@(none)> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
@(none)> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
需要給生產上root % 權限
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘XXX‘ WITH GRANT OPTION;
@(none)> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘XXX‘ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
@(none)> flush privileges;
Query OK, 0 rows affected (0.00 sec)
@(none)> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
生產環境可用mysql5.7.23安裝全過程