1.安装环境
CentOS版本:CentOS-7
[root@localhost usr]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
下载地址:http://www.centos.org/
MySQL版本:MySQL-5.6.22
来源:官网下载
下载地址:https://edelivery.oracle.com/EPD/Search/handle_go

2.卸载MariaDB
如果直接点击rpm包安装会得到错误提示。因为CentOS的默认数据库已经不再是MySQL了,而是MariaDB,为什么呢?
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。
开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。
MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

查看当前安装的mariadb包:
# rpm -qa | grep mariadb
将它们统统强制性卸载掉:
# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64
# rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64
# rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64

3.安装MYSQL
[root@localhost usr]# rpm -i MySQL-server-advanced-5.6.24-1.el7.x86_64.rpm
此版本的mysql的默认配置文件在/usr/my.cnf,控制台输出有说明。我修改了以下port进行测试,此配置文件却是有效的。如果mysql已经启动,可通过 ps -aux | grep mysqld 验证
[root@localhost usr]# rpm -i MySQL-client-advanced-5.6.24-1.el7.x86_64.rpm


4.启动MYSQL
[root@localhost usr]# systemctl start mysql

得到错误:ERROR!The server quit without updating PID file
我们这里主要是因为:selinux惹的祸,如果是centos系统,默认会开启selinux。解决方法是关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器。

然后再启动mysql就没问题了:
[root@localhost usr]# systemctl start mysql
查看MySQL运行状态:
[root@localhost usr]# systemctl status mysql
mysql.service - LSB: start and stop MySQL                                                                                                                               
   Loaded: loaded (/etc/rc.d/init.d/mysql)                                                                                                                              
   Active: active (exited) since 日 2015-04-19 11:30:09 CST; 19min ago                                                                                                  
  Process: 2691 ExecStop=/etc/rc.d/init.d/mysql stop (code=exited, status=0/SUCCESS)                                                                                    
  Process: 3117 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)                                                                                  
                                                                                                                                                                        
4月 19 11:30:09 localhost.localdomain mysql[3117]: Starting MySQL SUCCESS!                                                                                              
4月 19 11:30:09 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.     


5.首次登录MYSQL,会出现错误,在Linux系统中,必须先设置mysql中root用户的密码。
[root@localhost usr]# mysql -u root -p

6.重置MySQL中root用户密码及验证
(1) 停止MySQL服务
[root@localhost usr]# systemctl stop mysql
(2) 输入绕过密码认证命令
[root@localhost usr]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
(3) 登录mysql数据库
[root@localhost usr]# mysql -u root mysql
(4) 输入修改root密码SQL语句
mysql> UPDATE user SET password=PASSWORD('mypassword') where USER='root';
    Query OK, 4 rows affected (0.04 sec)
    Rows matched: 4 Changed: 4 Warnings: 0
(5) 输入数据刷新命令
 mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
(6) 退出
mysql> quit;
Bye

7.启动MYSQL
[root@localhost usr]# systemctl start mysql

8.登录mysql,查看所有数据库:
[root@bogon 桌面]# mysql -u root -p
mysql> show databases;
    ERROR 1820 (HY000):You must SET PASSWORD before executing this statement
还是有错误啊,提示要再设置一下密码:

    mysql> SET PASSWORD = PASSWORD('mypassword');

    Query OK, 0 rows affected (0.00 sec)
显示数据库:
mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | test |
    +--------------------+
    4 rows in set (0.00 sec)
    
    进入数据库创建表、显示表:
    mysql> use test;
    Database changed
    ...
Logo

更多推荐