您的位置:首页 > 运维架构 > Linux

Centos7下安装MySql5.6

2018-02-06 16:23 357 查看
一、开始

前往Mysql官网点击打开链接下载mysql 5.6,上传至centos7服务器上/usr/local/(哪个目录看个人习惯)



安装前必须删除原来的安装

需要检查 以下文件是否存在,如果存储则要删除之

/etc/my.cnf

/etc/init.d/mysqld

二、下载mysql依赖的库

shell> yum search libaio # search for info

shell> yum install libaio # install library

三、创建mysql
与用户组,-s /bin/false
表示该用户不能登录

shell> groupadd mysql

shell>useradd -r -g mysql
-s /bin/false mysql

四、解压安装包到指定目录

shell> tar zxvf
mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz

shell> ln -s
mysql-5.6.39-linux-glibc2.12-x86_64 mysql

shell> cd mysql

五、为mysql用户添加权限

shell> chown -R mysql
./

shell> chgrp -R mysql
./

#创建data目录并添加权限

shell> mkdir -p /data/mysql

shell> chown -R mysql:mysql /data/mysql

六、拷贝配置文件

shell> cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

#修改配置
vi /etc/my.cnf

#添加配置

[mysqld]

basedir=/usr/local/mysql

datadir=/data/mysql

character-set-server=utf8

#拷贝启动文件

shell> cp

/usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

七、初始化 mysql


shell>/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

八、添加环境变量

shell> vi /etc/profile

PATH=/usr/local/mysql/bin:$PATH

export PATH

#让刚才的修改生效

shell>source /etc/profile

九、启动数据库

shell> service mysql start

十、其他配置

#开机启动

chkconfig mysql on

 

#初始化mysql的一些设置

shell> ./usr/local/mysql/bin/mysql_secure_installation

#回车

Enter current password for root (enter for none):

#y,设置mysql的root密码

Set root password?[Y/n] y

#以下都yes

Remove anonymous users?[Y/n] y

Disallow root login remotely?[Y/n] y

Remove test database and access to it?[Y/n] y

Reload privilege tables now?[Y/n] y

ThanksforusingMySQL!

 

允许远程登陆方法一

1.   mysql> use mysql;

2.   mysql> select host,user,password from user;

3.   mysql> update user set password=password('123456')where user='root';

4.   mysql> update user set host='%' where user='root' andhost='localhost';

5.   mysql> flush privileges; 
允许远程登录方法二

1.   mysql>
use mysql;

2.   mysql>grant all privileges on *.* to 'root'@'%'identified by '123456' with grant option;

3.   mysql>flush privileges;

十一、补充

安装时的一些错误

-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter:
没有那个文件或目录

解决: yum -yinstall perl perl-devel

Installing MySQL system tables..../bin/mysqld: error while loadingshared libraries: libaio.so.1: cannot open shared object file: No such file ordirectory

解决:yum -y installlibaio-devel
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息