您好,登錄后才能下訂單哦!
生產環境安裝5.7.23全過程
先執行initialization.sh優化腳本 詳情見 Linux
在安裝mysql前,需要先查看一下是否清空了系統自帶了mysql
我們這里需要刪除系統自帶了mysql lib
我們先把mysql放置在/opt下
先上傳與線上版本一致的
[root@prd3-mysql01-180 opt]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 opt]# rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@prd3-mysql-0-36 opt]# find / -name "mysql"
/usr/share/mysql
/usr/lib64/mysql
[root@prd3-mysql-0-36 opt]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
[root@prd3-mysql-0-36 opt]# rpm -qa|grep mysql
[root@prd3-mysql-0-36 opt]# find / -name "mysql"
補充安裝相關的依賴 //要做,防止后面出錯
[root@ct6 ~]# yum -y install perl-Module-Install.noarch
[root@ct6 ~]# rpm -qa|grep 'perl-Module-Install'
perl-Module-Install-0.91-4.el6.noarch
第二步創建mysql的用戶
[root@prd3-mysql-0-36 opt]# groupadd mysql
[root@prd3-mysql-0-36 opt]# useradd -r -g mysql -s /bin/false mysql
第三步創建mysql的數據目錄[root@prd3-mysql-0-36 opt]# mkdir -p /ivargo/data/mysql
第三步:解壓 mysql安裝包到/usr/local 下
[root@prd3-mysql-0-36 opt]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
...
...
...
[root@prd3-mysql-0-36 opt]# cd /usr/local/
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 local]# mkdir mysql
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 local]# mv /usr/local/mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql
[root@prd3-mysql-0-36 local]# rm -rf mysql-5.7.23-linux-glibc2.12-x86_64/
[root@prd3-mysql-0-36 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 的權限
[root@prd3-mysql-0-36 local]# pwd
/usr/local
[root@prd3-mysql-0-36 local]# chown -R mysql:mysql mysql
第六步:修改mysql 配置文件
[root@prd3-mysql-0-36 local]# pwd
/usr/local
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 local]# cd mysql/
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 mysql]# cd support-files/
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 support-files]# find / -name "my.cnf"
[root@prd3-mysql-0-36 opt]# mv my.cnf /etc/
[root@prd3-mysql-0-36 opt]# ls -l /etc/my.cnf
-rw-r--r-- 1 root root 1649 Oct 11 2018 /etc/my.cnf
第七步:初始化mysql
[root@prd3-mysql-0-36 bin]# pwd
/usr/local/mysql/bin
初始化命令
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql
[root@prd3-mysql-0-36 bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/ivargo/data/mysql
...
...
...
第八步 :啟動mysql 并設置 開機自啟動 chkconfig mysql on
[root@prd3-mysql-0-36 bin]# service mysql start
Starting MySQL.. SUCCESS!
[root@prd3-mysql-0-36 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密碼
[root@prd3-mysql-0-36 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
[root@prd3-mysql-0-36 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)
[root@prd3-mysql-0-36 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)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。