RHEL 安装 mysql 5.6.24

RHEL 6.8
一、检查是否安装了mysql

[root@mysql ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-7.el6.x86_64
[root@mysql init.d]# rpm -e mysql-libs-5.1.73-7.el6.x86_64
error: Failed dependencies:
    libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64
    libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64
    mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64
卸载报错,卸载依赖包postfix,提示未安装
[root@mysql init.d]# rpm -e rpm -e postfix-2:2.6.6-6.el6_7.1.x86_64
error: package postfix-2:2.6.6-6.el6_7.1.x86_64 is not installed
卸载mysql-libs 加上 --nodeps 后缀
[root@mysql init.d]# rpm -e mysql-libs-5.1.73-7.el6.x86_64 --nodeps
卸载成功,再检查mysql安装包,已没有安装包

二、解压缩包
tar -xvf MySQL-5.6.24-1.el6.x86_64.rpm-bundle.tar
解压server及client包

[root@mysql tmp]# rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
提示warning 不存在mysql用户。。。
[root@mysql tmp]# rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
卸载安装包,更换解压方式
[root@mysql tmp]# rpm -qa | grep -i mysql
MySQL-client-5.6.24-1.el6.x86_64
MySQL-server-5.6.24-1.el6.x86_64
[root@mysql tmp]# rpm -e MySQL-client-5.6.24-1.el6.x86_64
[root@mysql tmp]# rpm -e MySQL-server-5.6.24-1.el6.x86_64
[root@mysql tmp]# rpm -qa | grep -i mysql
卸载完毕。
**重新解压安装**
为安装的rpm包授予执行权限
[root@mysql tmp]# chmod 755 MySQL*
[root@mysql tmp]# ll
总用量 436476
-rwxr-xr-x. 1 root root  223467520 82 22:29 MySQL-5.6.24-1.el6.x86_64.rpm-bundle.tar
-rwxr-xr-x. 1 7155 wheel  18509960 326 2015 MySQL-client-5.6.24-1.el6.x86_64.rpm
-rwxr-xr-x. 1 7155 wheel   3408004 326 2015 MySQL-devel-5.6.24-1.el6.x86_64.rpm
-rwxr-xr-x. 1 7155 wheel  88748476 326 2015 MySQL-embedded-5.6.24-1.el6.x86_64.rpm
-rwxr-xr-x. 1 7155 wheel  55782196 326 2015 MySQL-server-5.6.24-1.el6.x86_64.rpm
-rwxr-xr-x. 1 7155 wheel   1953680 326 2015 MySQL-shared-5.6.24-1.el6.x86_64.rpm
-rwxr-xr-x. 1 7155 wheel   3969728 326 2015 MySQL-shared-compat-5.6.24-1.el6.x86_64.rpm
-rwxr-xr-x. 1 7155 wheel  51088160 326 2015 MySQL-test-5.6.24-1.el6.x86_64.rpm
-rw-------. 1 root root          0 82 21:48 yum.log
优先安装兼容包MySQL-shared-compat-advanced-5.6.24-1.rhel5.x86_64.rpm,再安装server服务端程序、client客户端程序、devel库和头文件、shared共享库,test测试包可以不安装
安装时加后缀 --nodeps --force
[root@mysql tmp]# rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm  --nodeps --force
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
[root@mysql tmp]# rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm --nodeps --force
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[root@mysql tmp]# rpm -ivh MySQL-devel-5.6.24-1.el6.x86_64.rpm --nodeps --force
Preparing...                ########################################### [100%]
   1:MySQL-devel            ########################################### [100%]
[root@mysql tmp]# rpm -ivh MySQL-shared-compat-5.6.24-1.el6.x86_64.rpm --nodeps --force
Preparing...                ########################################### [100%]
   1:MySQL-shared-compat    ########################################### [100%]
[root@mysql tmp]# rpm -ivh MySQL-shared-5.6.24-1.el6.x86_64.rpm --nodeps --force
Preparing...                ########################################### [100%]
   1:MySQL-shared           ########################################### [100%]
[root@mysql tmp]# rpm -qa|grep -i mysql
MySQL-shared-compat-5.6.24-1.el6.x86_64
MySQL-server-5.6.24-1.el6.x86_64
MySQL-devel-5.6.24-1.el6.x86_64
MySQL-shared-5.6.24-1.el6.x86_64
MySQL-client-5.6.24-1.el6.x86_64
[root@mysql ~]# cat /root/.mysql_secret
# The random password set for the root user at Thu Aug  2 23:22:22 2018 (local time): _IBXKuDEnxhSAzvE
启动mysql服务
[root@mysql ~]# service mysql start
Starting MySQL.                                            [确定]
查询mysql的版本
[root@mysql ~]# mysqladmin --version
mysqladmin  Ver 8.42 Distrib 5.6.24, for Linux on x86_64
[root@mysqlshujuku ~]# mysql -u root -p
输入默认密码链接数据库,并修改root默认密码
mysql> SET PASSWORD FOR'root'@'localhost' = PASSWORD('12345678');
Query OK, 0 rows affected (0.00 sec)
退出数据库连接,并重启mysql服务
mysql> \q
Bye
[root@mysqlshujuku ~]# service mysql restart
Shutting down MySQL..                                      [确定]
Starting MySQL.                                            [确定]
重新连接数据库,验证修改后的root密码是否生效。

重启计算机后,连接mysql数据库失败,使用新密码及旧密码均失败,且重启mysql失败。

连接失败:
[root@mysqlshujuku ~]# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
重启mysql失败
[root@mysqlshujuku ~]# service mysql start
Starting MySQL.....................................................................................................The server quit without updating PID file (/var/lib/mysql/mysqlshujuku.pid).
检查启动进程
[root@mysqlshujuku ~]# ps -A | grep -i mysql
 1815 ?        00:00:00 mysqld_safe
 1916 ?        00:00:00 mysqld
 杀掉现有进程
[root@mysqlshujuku ~]# kill -9 1815 1916
[root@mysqlshujuku ~]# ps -A | grep -i mysql
启动mysql服务,成功
[root@mysqlshujuku ~]# service mysql start
Starting MySQL.                                            [确定]
[root@mysqlshujuku ~]# ps -A | grep -i mysql
 3465 pts/0    00:00:00 mysqld_safe
 3566 pts/0    00:00:00 mysqld
 连接数据库,使用新密码,成功(具体为什么在重启服务器后会出现连接mysql数据库失败及启动数据库失败的情况出现,要再查原因)。

创建数据库

创建数据库
mysql> show databases;
mysql> create database last;
授予权限
mysql> grant all privileges on last.* to last@'%' identified by 'last';

出错了
Query OK, 0 rows affected (0.04 sec)

ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation
Query OK, 0 rows affected (0.00 sec)

三、Mysql数据库操作。

连接数据库
[root@mysql home]# mysql -uroot -p
查现有数据库
mysql> show databases;
查看mysql.user的表结构
mysql> desc mysql.user;
查询mysql权限配置信息
mysql> select host,user,password from mysql.user;
创建用户,授予权限
mysql> grant all privileges on last.* to last@'%' identified by 'last2wq1';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

使用Navicat for Mysql报错2003,报错信息如下:
RHEL 安装 mysql 5.6.24_第1张图片
关闭防火墙及selinux后重启机器可正常连接。

创建表格:

mysql> use last;
Database changed
mysql> show tables;
Empty set (0.00 sec)

你可能感兴趣的:(运维)