Redhat6.5安装MySQL5.6 RPM包

时间:2022-08-27 10:25:16

以下内容转载自网络,因我自己操作过程中,有报错,所以汇总整理一下:

1.检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)

[root@localhost ~]#rpm -qa | grep -i mysql
mysql-libs-5.1.66-2.el6_3.x86_64
[root@localhost ~]#rpm -e mysql-libs-5.1.66-2.el6_3.x86_64 --nodeps

2. 下载Linux对应的RPM包,如Rethat6对应的RPM包如下:

[root@localhost RPM]# ll
total 458596
-rw-r--r-- 1 root root  18724760 May  6 19:27 MySQL-client-advanced-5.6.25-1.el6.x86_64.rpm
-rw-r--r-- 1 root root   3327796 May  6 19:27 MySQL-devel-advanced-5.6.25-1.el6.x86_64.rpm
-rw-r--r-- 1 root root  89610660 May  6 19:28 MySQL-embedded-advanced-5.6.25-1.el6.x86_64.rpm
-rw-r--r-- 1 root root  65951124 May  6 19:29 MySQL-server-advanced-5.6.25-1.el6.x86_64.rpm
-rw-r--r-- 1 root root   2031032 May  6 19:29 MySQL-shared-advanced-5.6.25-1.el6.x86_64.rpm
-rw-r--r-- 1 root root   3945172 May  6 19:29 MySQL-shared-compat-advanced-5.6.25-1.el6.x86_64.rpm
-rw-r--r-- 1 root root  51185604 May  6 19:30 MySQL-test-advanced-5.6.25-1.el6.x86_64.rpm
-rw-r--r-- 1 root root     15602 May 28 19:30 README.txt
-rw------- 1 ntsj ftp  234793042 Jul 31 15:30 V76360-01.zip

3.安装MySQL

[root@localhost rpm]# rpm -ivh MySQL-server-advanced-5.6.25-1.el6.x86_64.rpm
[root@localhost rpm]# rpm -ivh MySQL-devel-advanced-5.6.25-1.el6.x86_64.rpm
[root@localhost rpm]# rpm -ivh MySQL-client-advanced-5.6.25-1.el6.x86_64.rpm
#修改配置文件位置
[root@localhost rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf

4.初始化MySQL及设置密码

[root@localhost bin]# /usr/bin/mysql_install_db
[root@localhost bin]# service mysql start
[root@localhost bin]#mysql -uroot –p
mysql> SET PASSWORD = PASSWORD('123456');    #设置密码为123456
mysql> exit
[root@localhost ~]# mysql -uroot -p123456

我在这里启动Mysql服务的时候报错,如下:

Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

后边还有一大串,就不全粘贴在这里了,解决方法如下:

在运行初始化权限表的时候使用增加参数--datadir ,命令格式为:

shell> /usr/bin/mysql_install_db --user=mysql --datadir=/data/mysql/var


5.允许远程登录

mysql> use mysql;
mysql> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| 127.0.0.1             | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| ::1                   | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
+-----------------------+------+-------------------------------------------+
mysql> update user set password=password('123456') where user='root';
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit

6.设置开机自动启动

[root@localhost ~]# chkconfig mysql on
[root@localhost ~]# chkconfig --list | grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

7.MySQL的默认安装路径

/var/lib/mysql/               #数据库目录
/usr/share/mysql              #配置文件目录
/usr/bin                     #相关命令目录
/etc/init.d/mysql              #启动脚本

我上边已经改了数据库目录了,改到/data/mysql/var了。

8.修改字符集和数据存储路径

配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8。

[client]
password        = 123456
port            = 3306
default-character-set=utf8
[mysqld]
port            = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
datadir = /data/mysql/var
#(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)
lower_case_table_names=1
#(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )
max_connections=1000
[mysql]
default-character-set = utf8

9.查看字符集

show variables like '%collation%';
show variables like '%char%';