CentOS6.5安裝MySQL5.7.14

點擊打開鏈接

標籤: centosmysql
 7256人閱讀 評論(8) 收藏 舉報
 分類:
  

目錄(?)[+]

http://www.centoscn.com/mysql/2016/0711/7606.html

1. 下載安裝包

http://dev.mysql.com/downloads/mysql/5.7.html#downloads 
MySQL-5.7.14-Linux-glibc2.5-x86_64.tar.gz

2. 檢查庫文件是否存在,如有刪除。

[root@slave ~]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@slave ~]# rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
[root@slave ~]# rpm -qa | grep mysql
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

3. 檢查mysql組和用戶是否存在,如無創建。

[root@slave ~]# cat /etc/group | grep mysql
[root@slave ~]# cat /etc/passwd | grep mysql

// useradd -r參數表示mysql用戶是系統用戶,不可用於登錄系統。
[root@slave ~]# groupadd mysql
[root@slave ~]# useradd -r -g mysql mysql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4. 解壓TAR包,更改所屬的組和用戶

[root@slave zkpk]# cd /usr/local/
[root@slave local]# tar -xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz 
[root@slave local]# mv mysql-5.7.14-linux-glibc2.5-x86_64 mysql
[root@slave local]# ll
total 628304
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. 8 root root       4096 Sep 27  2014 jdk1.7.0_71
drwxr-xr-x. 8 root root       4096 Apr 11  2015 jdk1.8.0_45
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 7161 31415      4096 Jul 12 21:03 mysql
-rw-r--r--. 1 zkpk zkpk  642694570 Aug 20 00:57 mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 2 root root       4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root       4096 Jul 30 21:17 share
drwxr-xr-x. 2 root root       4096 Sep 23  2011 src
[root@slave local]# rm mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz 
rm: remove regular file `mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz'? y
[root@slave local]# chown -R mysql:mysql mysql/
[root@slave local]# cd mysql/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

5. 安裝和初始化數據庫

配置OS

sudo vim /etc/security/limits.conf

mysql hard nofile 65535
mysql soft nofile 65535
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

安裝與初始化DB

[root@slave mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-08-20 01:18:44 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-08-20 01:18:47 [WARNING] The bootstrap log isn't empty:
2016-08-20 01:18:47 [WARNING] 2016-08-19T17:18:44.728642Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-08-19T17:18:44.729178Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-08-19T17:18:44.729183Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

如果改變默認安裝路徑,則需要 
1. /etc/my.cnf、/etc/init.d/mysqld中修改: 
basedir=’/apps/mysql’ datadir=’/apps/mysql/data’ 
2. 創建ln: 
ln -s  /usr/local/mysql/bin/mysql  /usr/bin

[root@slave mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
[root@slave mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld
  • 1
  • 2
  • 1
  • 2
[root@slave mysql]# cd bin/
[root@slave bin]# ./mysqld_safe --user=mysql &
[1] 2966
[root@slave bin]# 2016-08-19T17:24:36.174662Z mysqld_safe Logging to '/usr/local/mysql/data/slave.err'.
2016-08-19T17:24:36.207209Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@slave bin]# 
[root@slave bin]# 
[root@slave bin]# 
[root@slave bin]# 
[root@slave bin]# /etc/init.d/mysqld restart
Shutting down MySQL..2016-08-19T17:25:18.416810Z mysqld_safe mysqld from pid file /usr/local/mysql/data/slave.pid ended
                                                           [  OK  ]
Starting MySQL.                                            [  OK  ]
[1]+  Done                    ./mysqld_safe --user=mysql
[root@slave bin]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

設置開機啓動

[root@slave bin]# chkconfig --level 35 mysqld on
  • 1
  • 1

6. 初始化密碼

[root@slave bin]# cat /root/.mysql_secret 
# Password set for user 'root@localhost' at 2016-08-20 01:18:44 
eqW;ehX;>-YG
[root@slave 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.14

Copyright (c) 2000, 2016, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

7. 添加遠程訪問權限

mysql> use mysql; 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select host, user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
+-----------+-----------+

//重啓生效
/etc/init.d/mysqld restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

8. 修改字符集

[root@slave mysql]# vim /etc/my.cnf 

[mysqld]
...略
character-set-server=utf8

//重啓生效
/etc/init.d/mysqld restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

9. linux下mysql配置文件my.cnf詳解

http://www.cnblogs.com/captain_jack/archive/2010/10/12/1848496.html

10. 卸載MySQL

# 1. 停止服務
/etc/init.d/mysqld stop

# 2. 停止並刪除開機啓動
chkconfig mysqld off
chkconfig --del mysqld

# 3. 刪除MySQL目錄
rm -rf /usr/local/mysql
rm -f /etc/my.cnf
rm -f /etc/init.d/mysqld
rm -f /root/.mysql_secret

# 4. 刪除用戶和用戶組
userdel -r mysql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

11. 參考

Linux添加/刪除用戶和用戶組 Linux 用戶(user)和用戶組(group)

Linux下chkconfig命令詳解

Linux中find常見用法示例

CentOS7安裝mysql5.6.23

win7 64位下如何安裝配置mysql-5.7.4-m14-winx64

MySQL5.6下載地址

標籤: centosmysql
 7256人閱讀 評論(8) 收藏 舉報
 分類:
  

目錄(?)[+]

http://www.centoscn.com/mysql/2016/0711/7606.html

1. 下載安裝包

http://dev.mysql.com/downloads/mysql/5.7.html#downloads 
MySQL-5.7.14-Linux-glibc2.5-x86_64.tar.gz

2. 檢查庫文件是否存在,如有刪除。

[root@slave ~]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@slave ~]# rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
[root@slave ~]# rpm -qa | grep mysql
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

3. 檢查mysql組和用戶是否存在,如無創建。

[root@slave ~]# cat /etc/group | grep mysql
[root@slave ~]# cat /etc/passwd | grep mysql

// useradd -r參數表示mysql用戶是系統用戶,不可用於登錄系統。
[root@slave ~]# groupadd mysql
[root@slave ~]# useradd -r -g mysql mysql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4. 解壓TAR包,更改所屬的組和用戶

[root@slave zkpk]# cd /usr/local/
[root@slave local]# tar -xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz 
[root@slave local]# mv mysql-5.7.14-linux-glibc2.5-x86_64 mysql
[root@slave local]# ll
total 628304
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. 8 root root       4096 Sep 27  2014 jdk1.7.0_71
drwxr-xr-x. 8 root root       4096 Apr 11  2015 jdk1.8.0_45
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 7161 31415      4096 Jul 12 21:03 mysql
-rw-r--r--. 1 zkpk zkpk  642694570 Aug 20 00:57 mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 2 root root       4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root       4096 Jul 30 21:17 share
drwxr-xr-x. 2 root root       4096 Sep 23  2011 src
[root@slave local]# rm mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz 
rm: remove regular file `mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz'? y
[root@slave local]# chown -R mysql:mysql mysql/
[root@slave local]# cd mysql/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

5. 安裝和初始化數據庫

配置OS

sudo vim /etc/security/limits.conf

mysql hard nofile 65535
mysql soft nofile 65535
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

安裝與初始化DB

[root@slave mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-08-20 01:18:44 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-08-20 01:18:47 [WARNING] The bootstrap log isn't empty:
2016-08-20 01:18:47 [WARNING] 2016-08-19T17:18:44.728642Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-08-19T17:18:44.729178Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-08-19T17:18:44.729183Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

如果改變默認安裝路徑,則需要 
1. /etc/my.cnf、/etc/init.d/mysqld中修改: 
basedir=’/apps/mysql’ datadir=’/apps/mysql/data’ 
2. 創建ln: 
mkdir -p /usr/local/mysql/bin

[root@slave mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
[root@slave mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld
  • 1
  • 2
  • 1
  • 2
[root@slave mysql]# cd bin/
[root@slave bin]# ./mysqld_safe --user=mysql &
[1] 2966
[root@slave bin]# 2016-08-19T17:24:36.174662Z mysqld_safe Logging to '/usr/local/mysql/data/slave.err'.
2016-08-19T17:24:36.207209Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@slave bin]# 
[root@slave bin]# 
[root@slave bin]# 
[root@slave bin]# 
[root@slave bin]# /etc/init.d/mysqld restart
Shutting down MySQL..2016-08-19T17:25:18.416810Z mysqld_safe mysqld from pid file /usr/local/mysql/data/slave.pid ended
                                                           [  OK  ]
Starting MySQL.                                            [  OK  ]
[1]+  Done                    ./mysqld_safe --user=mysql
[root@slave bin]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

設置開機啓動

[root@slave bin]# chkconfig --level 35 mysqld on
  • 1
  • 1

6. 初始化密碼

[root@slave bin]# cat /root/.mysql_secret 
# Password set for user 'root@localhost' at 2016-08-20 01:18:44 
eqW;ehX;>-YG
[root@slave 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.14

Copyright (c) 2000, 2016, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

7. 添加遠程訪問權限

mysql> use mysql; 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select host, user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
+-----------+-----------+

//重啓生效
/etc/init.d/mysqld restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

8. 修改字符集

[root@slave mysql]# vim /etc/my.cnf 

[mysqld]
...略
character-set-server=utf8

//重啓生效
/etc/init.d/mysqld restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

9. linux下mysql配置文件my.cnf詳解

http://www.cnblogs.com/captain_jack/archive/2010/10/12/1848496.html

10. 卸載MySQL

# 1. 停止服務
/etc/init.d/mysqld stop

# 2. 停止並刪除開機啓動
chkconfig mysqld off
chkconfig --del mysqld

# 3. 刪除MySQL目錄
rm -rf /usr/local/mysql
rm -f /etc/my.cnf
rm -f /etc/init.d/mysqld
rm -f /root/.mysql_secret

# 4. 刪除用戶和用戶組
userdel -r mysql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

11. 參考

Linux添加/刪除用戶和用戶組 Linux 用戶(user)和用戶組(group)

Linux下chkconfig命令詳解

Linux中find常見用法示例

CentOS7安裝mysql5.6.23

win7 64位下如何安裝配置mysql-5.7.4-m14-winx64

MySQL5.6下載地址

發佈了1 篇原創文章 · 獲贊 15 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章