Centos 6.5下安装MySQL 5.6

前端之家收集整理的这篇文章主要介绍了Centos 6.5下安装MySQL 5.6前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.下载Linux对应的RPM包

http://dev.mysql.com/downloads/mysql/5.6.html

wget http://cdn.MysqL.com//Downloads/MysqL-5.6/MysqL-5.6.33-1.el6.x86_64.rpm-bundle.tar

2.解压tar包

tar -xvf MysqL-5.6.33-1.el6.x86_64.rpm-bundle.tar

3.安装MysqL

rpm -ivh MysqL-server-5.6.33-1.el6.x86_64.rpm 
rpm -ivh MysqL-client-5.6.33-1.el6.x86_64.rpm 
rpm -ivh MysqL-devel-5.6.33-1.el6.x86_64.rpm

如果出现:

error: Failed dependencies:
        libaio.so.1()(64bit) is needed by MysqL-server-5.6.33-1.el6.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by MysqL-server-5.6.33-1.el6.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by MysqL-server-5.6.33-1.el6.x86_64

下载libaio

yum install libaio

如果出现:

error: Failed dependencies:
        libnuma.so.1()(64bit) is needed by MysqL-server-5.6.33-1.el6.x86_64
        libnuma.so.1(libnuma_1.1)(64bit) is needed by MysqL-server-5.6.33-1.el6.x86_64
        libnuma.so.1(libnuma_1.2)(64bit) is needed by MysqL-server-5.6.33-1.el6.x86_64

下载numactl

yum install numactl

4.初始化MysqL及设置密码

/usr/bin/MysqL_install_db
service MysqL start

如果启动失败可能是数据块所在目录没有权限

cat /root/.MysqL_secret  #查看root账号密码
MysqL> SET PASSWORD = PASSWORD('123456');
MysqL> exit

如果.MysqL_secret文件不存在,先停止MysqL进入安全模式设置密码

service MysqL stop
MysqLd_safe --skip-grant-tables&
MysqL -u root MysqL
MysqL> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
MysqL> FLUSH PRIVILEGES;

5.允许远程登陆

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

6.设置开机自启动

chkconfig MysqL on
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              #启动脚本

8.常用命令

1.使用客户端工具连接到数据库

MysqL -u root -p

2.查看MysqL服务器中包含那些数据库

MysqL>SHOW DATABASES;

3.查看数据库中的数据表信息

MysqL>SHOW TABLES;

4.切换数据库

MysqL>USE MysqL;

5.创建新的数据库

MysqL>CREATE DATABASE 数据库名字;

6.创建新的数据表

MysqL>CREATE TABLE 表名 (字段定义)

7.删除一个数据表

MysqL>DROP TABLE 数据库名.表名;

8.删除一个数据库

MysqL>DROP DATABASE 数据库

9.备份整个数据库

MysqLdump -u root -p auth > MysqL-auth.sql

10.备份数据库MysqL中的user表

MysqLdump -u root -p MysqL user > MysqL.host-user.sql

11.备份MysqL服务器中所有数据库

MysqLdump -u root -p -all-databases > MysqL-all.sql

12.恢复数据库

MysqL -u root -p [数据库名]< MysqL-all.sql

13.授予用户权限

GRANT 权限列表 ON 数据库名.表名 TO 用户名@来源地址 [IDENTIFIED BY '密码']
GRANT SELECT ON MysqL.user TO daxiong@'localhost' IDENTIFIED BY'123456';

猜你在找的CentOS相关文章