六月 8th, 2016

如何在RedHat Linux环境下安装MySQL数据库

数据库问题解决方案, by 小哥.

==============================卸载本机已安装的MySQL================================
[root@cloud opt]# rpm -qa | grep -i mysql
MySQL-client-5.5.16-1.rhel4.i386
MySQL-devel-5.5.16-1.rhel4.i386
MySQL-server-5.5.16-1.rhel4.i386

[root@cloud opt]# rpm -e –nodeps MySQL-client-5.5.16-1.rhel4.i386
[root@cloud opt]# rpm -e –nodeps MySQL-devel-5.5.16-1.rhel4.i386
[root@cloud opt]# rpm -e –nodeps MySQL-server-5.5.16-1.rhel4.i386

[root@cloud opt]# rpm -qa | grep -i mysql
[root@cloud opt]#

==========================下载32位MySQL安装包=====================================
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.6.17-1.linux_glibc2.5.i386.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.6.17-1.linux_glibc2.5.i386.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.6.17-1.linux_glibc2.5.i386.rpm

==========================下载64位MySQL安装包=====================================
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.6.15-1.el6.x86_64.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.6.15-1.el6.x86_64.rpm
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.6.15-1.el6.x86_64.rpm

==========================执行安装32位MySQL=======================================
rpm -ivh MySQL-server-5.6.17-1.linux_glibc2.5.i386.rpm
rpm -ivh MySQL-client-5.6.17-1.linux_glibc2.5.i386.rpm
rpm -ivh MySQL-devel-5.6.17-1.linux_glibc2.5.i386.rpm

==========================执行安装64位MySQL=======================================
rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm
rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm

==========================复制my.cnf至/etc/my.cnf====================================
cp /usr/share/mysql/my-default.cnf /etc/my.cnf

==========================启动MySQL服务和配置=====================================
[root@cloud /]# service mysql start
Starting MySQL.. SUCCESS!

[root@cloud /]# mysql -uroot -p
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 6
Server version: 5.6.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> SET PASSWORD = PASSWORD(‘123456’);
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’WITH GRANT OPTION;
Query OK, 0 rows affected (0.07 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

[root@cloud /]# mysql -uroot -p123456 -hxxx.xxx.xxx.xxx(主机IP地址)
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 6
Server version: 5.6.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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>

=============================MySQL异常问题=====================================
远程无法登陆
[root@cloud /]# service mysql stop
Shutting down MySQL.. SUCCESS!
[root@cloud /]# ps -ef | grep mysql
root 4981 2100 0 Jun07 pts/1 00:00:00 mysql -uroot -px xxxx
root 5282 2100 0 00:02 pts/1 00:00:00 grep mysql
[root@cloud /]# kill -9 4981
[root@cloud /]#
[1]+ 已杀死 mysql -uroot -p123456
[root@cloud /]# service mysql start
Starting MySQL. SUCCESS!

[root@cloud /]# mysql -uroot -p123456 -hxxx.xxx.xxx.xxx(主机IP地址)
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 2
Server version: 5.6.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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>
================================备注============================================
启动脚本:/etc/init.d/mysql
数据库目录:/var/lib/mysql/
数据库目录:/var/lib/mysql/
配置文件目录:/usr/share/mysql
MySQL Bin目录:/usr/bin

Back Top