CentOS6.5安装MySql5.6

CentOS6.5安装MySql5.6

微信搜索 zze_coding 或扫描 👉 二维码关注我的微信公众号获取更多资源推送:

下载

官网下载:https://downloads.mysql.com/archives/community/

image.png

安装

1、先卸载 mysql 相关的东西:

yum remove mysql mysql-server mysql-libs mysql-server;

2、查询是否还有,如果有,继续 remove:

rpm -qa|grep mysql

3、解压:

[root@zze mysql]# tar xvf MySQL-5.6.41-1.el6.x86_64.rpm-bundle.tar 
MySQL-client-5.6.41-1.el6.x86_64.rpm
MySQL-shared-compat-5.6.41-1.el6.x86_64.rpm
MySQL-test-5.6.41-1.el6.x86_64.rpm
MySQL-server-5.6.41-1.el6.x86_64.rpm
MySQL-devel-5.6.41-1.el6.x86_64.rpm
MySQL-shared-5.6.41-1.el6.x86_64.rpm
MySQL-embedded-5.6.41-1.el6.x86_64.rpm

4、安装 mysql 服务:

[root@zze mysql]# rpm -ivh MySQL-server-5.6.41-1.el6.x86_64.rpm 
warning: MySQL-server-5.6.41-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
    /usr/bin/perl is needed by MySQL-server-5.6.41-1.el6.x86_64
    libaio.so.1()(64bit) is needed by MySQL-server-5.6.41-1.el6.x86_64
    libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.41-1.el6.x86_64
    libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.41-1.el6.x86_64
    libnuma.so.1()(64bit) is needed by MySQL-server-5.6.41-1.el6.x86_64
    libnuma.so.1(libnuma_1.1)(64bit) is needed by MySQL-server-5.6.41-1.el6.x86_64
    libnuma.so.1(libnuma_1.2)(64bit) is needed by MySQL-server-5.6.41-1.el6.x86_64

安装它需要很多依赖,依次安装完再次执行上述即可:

yum -y install perl
yum -y install libaio
yum -y install 'libnuma.so.1()(64bit)'

5、安装客户端:

rpm -ivh MySQL-client-5.6.41-1.el6.x86_64.rpm

6、启动 mysql 服务,检查是否安装成功:

[root@zze mysql]# service mysql status
 ERROR! MySQL is not running
[root@zze mysql]# service mysql start
Starting MySQL.Logging to '/var/lib/mysql/zze.err'.
....... SUCCESS!

修改密码

查看 mysql 随机密码,用随机密码登录 root 账户:

[root@zze mysql]# cat /root/.mysql_secret 
# The random password set for the root user at Sat Jan 12 17:39:19 2019 (local time): CuPRD_mpF9Dk41_q

[root@zze mysql]# mysql -uroot -pCuPRD_mpF9Dk41_q
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

修改 root 密码:

mysql> set password=password('root');
Query OK, 0 rows affected (0.00 sec)

加入系统服务

chkconfig --add mysql # 加入系统服务
chkconfig mysql on # 开机自启

查看:

[root@zze my.cnf.d]# chkconfig | grep -i mysql
mysql              0:off    1:off    2:on    3:on    4:on    5:on    6:off

2、3、4、5 状态为 on 即可。

设置远程访问

查看系统开放访问的端口:

[root@zze ~]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
   ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
   ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
   ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

让 3306 端口可被访问:

[root@zze ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
[root@zze ~]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3306 
   ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
   ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
   ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

授权 root 可远程访问:

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

添加配置文件

新建 /etc/my.cnf 文件,内容如下:

[client]
user = root
password = root
port            = 3306  
default-character-set=utf8  
[mysqld]
# 取消一些检查,如果远程连接很慢可以去掉这行
skip-name-resolve  
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

Copyright: 采用 知识共享署名4.0 国际许可协议进行许可

Links: https://www.zze.xyz/archives/centos6-install-mysql56.html

Buy me a cup of coffee ☕.