1、查看CentOS自带MySQL 5.1组件并卸载

    rpm -qa | grep -i mysql  

    rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64 

2、rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm

   rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm

3、rpm -ivh mysql-community-common-5.7.18-1.el6.x86_64.rpm  

   rpm -ivh mysql-community-libs-5.7.18-1.el6.x86_64.rpm  

   rpm -ivh mysql-community-client-5.7.18-1.el6.x86_64.rpm  

   rpm -ivh mysql-community-server-5.7.18-1.el6.x86_64.rpm  

   wKioL1kJNp3BXml1AABJ9do2p0Y957.png

4. 修改数据库编码。

     为了保证数据库能正确处理中文,我们需要设定数据库默认的编码为utf8。修改/etc/my.cnf文件,并在其中加入以下内容:


     [client]  

     default-character-set=utf8mb4  

  

     [mysqld]  

     character_set_server=utf8mb4  

     wKioL1kJNk6QSMhnAABlTk_fQMk222.png

5、修改时区

wKioL1lB73vzFVc_AAC0M4Uqbrw626.png

6、启动MySQL

    service mysqld start  

wKiom1kJNuDTIxMdAAARpMKVvg0487.png

6、mysql登录及修改密码

   mysql -u root -p

wKioL1kJOIKwqjvyAAA1xQtmE8Y425.png

7、在CentOS系统中防火墙默认是阻止3306端口的,现在开启3306端口

   修改/etc/sysconfig/iptables 文件,添加以下内容:

wKioL1kJUPXzWBtMAADHHZsf5UU386.png


查询防火墙状态:

[root@localhost ~]# service   iptables status<回车>

停止防火墙:

[root@localhost ~]# service   iptables stop <回车>

启动防火墙:

[root@localhost ~]# service   iptables start <回车>

重启防火墙:

[root@localhost ~]# service   iptables restart <回车>

永久关闭防火墙:

[root@localhost ~]# chkconfig   iptables off<回车>

永久关闭后启用:

[root@localhost ~]# chkconfig   iptables on<回车>

重启防火墙:

1)、重启后永久性生效:

开启:chkconfig iptables on

关闭:chkconfig iptables off

2)、即时生效,重启后失效:

开启:service iptables start

关闭:service iptables stop需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭操作。

wKioL1kJUZvQUMzDAAC8I5gU1Ps494.png

------------------------------------华丽分割线---------------------------------------

 启动mysql的时候解决错误:Fatal error: mysql.user table is damaged. Please run mysql_upgrade.

 1、rm -rf /var/lib/mysql/

 2、使用如下命令,重新初始化mysql

    mysqld --initialize --user=mysql

 3、service mysqld start 

------------------------------------华丽分割线---------------------------------------

修改root密码报错解决:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) :表示没有生成root的临时密码

1、service mysqld stop   停掉mysql服务器

   wKioL1kJN5-BJqAhAAAS8DH4rII682.png

2、mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

   wKioL1kJN7Swp8mAAABB7vB35uU159.png

3、show databases;

   use mysql;

   show tables;

4、update user set authentication_string=PASSWORD('root123!@#') where user='root';

   flush privileges;

   exit;

wKiom1kJOdSh_y5uAAAtLmhSUVI073.png

------------------------------------华丽分割线---------------------------------------

   解决错误:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

   1、SET PASSWORD = PASSWORD('root123!@#');

   2、flush privileges;

   3、exit;

wKiom1kJO17D5W1UAABoYoFWJzg839.png