CentOS6.5以RPM方式安装MySQL-5.6.20

本文详细介绍如何在Linux环境下安装MySQL,并提供了配置步骤及常见问题解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 如果本机已经安装了先卸载

版本过老不推荐使用,仅供参考

1.1 查询是否已经安装
rpm -qa | grep -i mysql
1.2 如果安装了先卸载(没有安装请忽略)
yum -y remove mysql

2 下载需要的安装包

链接可能会随着时间的推移而失效,如果链接失效,请自行去官网查找

http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.20-1.el6.x86_64.rpm
http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-devel-5.6.20-1.el6.x86_64.rpm
http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.20-1.el6.x86_64.rpm

3 安装

rpm -ivh MySQL-server-5.6.20-1.el6.x86_64.rpm
rpm -ivh MySQL-devel-5.6.20-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.20-1.el6.x86_64.rpm

4 修改配置文件位置并做相关设置

cp /usr/share/mysql/my-default.cnf /etc/my.cnf
vi /etc/my.cnf

自定义自己的配置(以下只是示例)

[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
#linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写。
lower_case_table_names=1
#设置最大连接数,默认为151,MySQL服务器允许的最大连接数16384
max_connections=1000
[mysql]
default-character-set = utf8 

5 初始化MySQL并启动服务

/usr/bin/mysql_install_db
service mysql start

6 登录并设置密码

首次安装没有密码,直接登录

mysql -uroot -p
#设置root用户的密码
update user set password=password('123456') where user='root';

7 设置允许远程登录(根据自己需求)

mysql> use mysql;
mysql> select host,user,password from user;
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit;

8 设置开机启动

chkconfig mysql on
chkconfig --list | grep mysql

9 相关配置的默认位置

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

卸载mysql的时候,将这些目录下的文件也一并删掉。

10 可能遇到的错误

10.1 不能正常的创建表空间

2014-01-21 06:03:29 14964 [ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if      non-zero) pages!
2014-01-21 06:03:29 14964 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you   should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of  zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2014-01-21 06:03:29 14964 [ERROR] Plugin 'InnoDB' init function returned error.
2014-01-21 06:03:29 14964 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2014-01-21 06:03:29 14964 [ERROR] Unknown/unsupported storage engine: InnoDB
2014-01-21 06:03:29 14964 [ERROR] Aborting

在/var/lib/mysql/目录下删掉这三个文件:ibdata1、ib_logfile0、ib_logfile1 然后重启服务。

cd /var/lib/mysql
rm ibdata1 ib_logfile0 ib_logfile1
service mysql start

10.2 不能正常登录

[root@localhost local]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
方法操作很简单,如下:

解决方案:先停止服务、再设置跳过授权表,然后重新设置密码,重启服务并重新登录

/etc/init.d/mysql stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -u root mysql
#把空的用户密码都修改成非空的密码。
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='root' or host='localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit 
/etc/init.d/mysqld restart

10.3 You must SET PASSWORD before executing this statement.

mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

要求重新设置一次密码

mysql>  SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected (0.03 sec)
mysql> create database roger;
Query OK, 1 row affected (0.00 sec)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值