CentOS6.5编译安装MySQL5.7.14

1. 下载安装包

MySQL-5.7.14-Linux-glibc2.5-x86_64.tar.gz

地址:http://dev.mysql.com/get/Downloads/MySQL-5.7/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]# rm -rf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz 
  • 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 local]#mkdir -p /usr/local/mysql/data
[root@slave local]# chown -R mysql:mysql mysql/[root@slave local]# cd mysql/
[root@slave mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/  --datadir=/usr/local/mysql/data/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

如果需要改变默认安装路径,则 
/etc/my.cnf、/etc/init.d/mysqld中修改: 
basedir=’/apps/mysql’ datadir=’/apps/mysql/data’ 

[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: 

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; 
mysql> update user set host = '%' where user = 'root';或者mysql>grant all privileges on *.* to root@'%' identified by '123456' with grant option;

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下载地址


你可能感兴趣的:(Mysql,Linux)