CentOS-7下安裝MySQL5.6.22

參考: http://www.2cto.com/database/201501/371451.htmlhtml

安裝環境   CentOS版本:CentOS-7node

由於以前安裝過,沒有成功,可是有以前安裝的文件,要先卸載mysql

網上找了一個卸載的過程以下:linux

 a)查看系統中是否以rpm包安裝的mysql:sql

[root@centos7 ~]# rpm -qa | grep -i mysql
MySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686
b)卸載mysql
[root@centos7 ~]# rpm -e MySQL-server-5.6.17-1.el6.i686
[root@centos7 ~]# rpm -e MySQL-client-5.6.17-1.el6.i686
c)刪除mysql服務
[root@centos7 ~]# chkconfig --list | grep -i mysql
[root@centos7 ~]# chkconfig --del mysql
d)刪除分散mysql文件夾
[root@centos7 ~]# whereis mysql 或者 find / -name mysql數據庫

 mysql: /usr/lib/mysql /usr/share/mysqlwindows

清空相關mysql的全部目錄以及文件
[root@centos7 ~]#rm -rf /usr/lib/mysql
[root@centos7 ~]#rm -rf /usr/share/mysql
[root@centos7 ~]#rm -rf /usr/my.cnfcentos

 

下載並安裝  官網下載dom

1. 解壓下載的zip包,會發現有如下幾個rpm包:ide

MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-embedded-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-test-advanced-5.6.22-1.el7.x86_64.rpm

 

2. 卸載MariaDB(這一步沒操做過)

若是直接點擊rpm包安裝會獲得錯誤提示。由於CentOS的默認數據庫已經再也不是MySQL了,而是MariaDB,爲何呢?

MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL受權許可。開發這個分支的緣由之一是:甲骨文公司收購了MySQL後,有將MySQL閉源的潛在風險,所以社區採用分支的方式來避開這個風險。MariaDB的目的是徹底兼容MySQL,包括API和命令行,使之能輕鬆成爲MySQL的代替品。

查看當前安裝的mariadb包:

[root@centos7 ~]# rpm -qa | grep mariadb

將它們通通強制性卸載掉:

[root@centos7 ~]# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64

[root@centos7 ~]# rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64

[root@centos7 ~]# rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64

 

3. 安裝MYSQL

按順序執行

rpm -ivh MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm
rpm -ivh MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm
rpm -ivh MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

 完成..  

4. 啓動MYSQL

[root@centos7 mysql]#service mysql start

查看MySQL運行狀態:

[root@centos7 mysql]# service mysql status

SUCCESS! MySQL running (14158)

 

5. 默認root用戶登陸MYSQL

[root@centos7 mysql]# mysql -u root -p

Enter password:

ERROR 1045 (28000):Access denied for user 'root'@'localhost' (using password: YES)

發現有有錯誤,而後在網上查了一下說使用下面命令修改root初始化密碼:

[root@centos7 mysql]# /usr/bin/mysqladmin -u root password 'passok'

/usr/bin/mysqladmin: connect to server at'localhost' failed

error: 'Accessdenied for user 'root'@'localhost' (using password: NO)'

發現MYSQL數據庫默認的root用戶仍是沒辦法設置密碼進行登陸,須要作一下操做:

 

重置MySQL中root用戶密碼及驗證

仍是不行,而後在網上又找到一個重置MySQL中root用戶密碼及驗證的方法:

(1) 中止MySQL服務

[root@centos7 mysql]# service mysql stop

Shutting down MySQL.. SUCCESS!

(2) 輸入繞過密碼認證命令

[root@centos7 mysql]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

[1] 5807

150117 22:23:31 mysqld_safe Logging to '/var/lib/mysql/bogon.err'.

150117 22:23:31 mysqld_safe Starting mysqlddaemon with databases from /var/lib/mysql

(3) 輸入登陸用戶命令

[root@centos7 mysql]# mysql -u root mysql

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version:5.6.22-enterprise-commercial-advanced MySQL Enterprise Server - AdvancedEdition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

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

(4)添加用戶並賦予權限

mysql> use mysql;

mysql> create database MyShop; //建立一個數據庫

//建立一個用戶www並具備操做MyShop數據庫的權限

mysql> grant all privileges on MyShop.* to 'www'@'localhost' identified by '888888';
mysql> flush privileges;

 

若是出現: The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement

要先執行一下flush privileges,而後在執行 grant all 來建立用戶

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

 

來查看一下權限

mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM user;
+------------------------------+
| query |
+------------------------------+
| User: 'root'@'127.0.0.1'; |
| User: 'root'@'::1';          |
| User: 'root'@'centos7';   |
| User: 'www'@'localhost'; |
| User: 'root'@'localhost'; |
+------------------------------+
6 rows in set (0.00 sec)


mysql> show grants for 'www'@'localhost';
+----------------------------------------------------------------------------------------------------------------+
| Grants for www@localhost                                     |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'www'@'localhost' IDENTIFIED BY PASSWORD '*8E02B7AE57F9A19E165EB45CD3F705BF66985B85' |
| GRANT ALL PRIVILEGES ON `MyShop`.* TO 'www'@'localhost'                 |
+----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

(5) 輸入修改root密碼SQL語句

mysql> udpate user SET Password=PASSWORD('root') where USER='root';

Query OK, 4 rows affected (0.04 sec)

Rows matched: 4 Changed: 4 Warnings: 0

(6) 輸入數據刷新命令

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

(7) 退出

mysql> quit

Bye

(8) 啓動MYSQL

[root@centos7 mysql]# service mysql start

Starting MySQL SUCCESS!

 

登陸mysql,查看全部數據庫:

[root@centos7 mysql]# mysql -u root -p

mysql> show databases;

ERROR 1820 (HY000):You must SET PASSWORD before executing this statement

提示要再設置一下密碼:

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

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

mysql> show tables;

Empty set (0.02 sec)

mysql>create table testTable(name char(15) not null,passwd char(15) not null);

Query OK, 0 rows affected (0.87 sec)

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| testTable |

+----------------+

1 row in set (0.00 sec)

 

mysql安裝後三個主要的目錄及其功能:

/var/lib/mysql 數據庫文件

/usr/share/mysql 命令及配置文件

/usr/bin mysqladmin、mysqldump等命令

 

設置mysql開機自啓動

設置開機啓動服務選擇使用chkconfig命令,能夠看到咱們永久性關閉iptables就用的這個命令,命令的格式以下:

chkconfig 功能說明:檢查,設置系統的各類服務。

語法:chkconfig [--add][--del][--list][系統服務]或 chkconfig [--level <等級代號>][系統服務][on/off/reset]

--add 添加服務

--del 刪除服務

--list 查看各服務啓動狀態

 

我這裏安裝好了mysql以後默認就是開機自啓動的:

[root@centos7 mysql]# chkconfig --list mysql

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。

若是您想列出 systemd 服務,請執行 'systemctl list-unit-files'。

欲查看對特定 target 啓用的服務請執行

'systemctl list-dependencies [target]'。

mysql 0:關 1:關 2:開 3:開 4:開 5:開 6:關

若是不是開機自啓動,使用開啓MySQL服務自動開啓命令:

chkconfig mysqld on

chkconfig mysql on

 

蒐集的安裝過程當中遇到的問題:

1: 啓動時
[root@centos7 mysql]#service mysql start
獲得錯誤:ERROR!The server quit without updating PID file
這裏主要是由於:selinux惹的禍,若是是centos系統,默認會開啓selinux。
解決方法是關閉它,打開/etc/selinux/config,把SELINUX=enforcing改成SELINUX=disabled後存盤退出重啓機器。
而後再啓動mysql就沒問題了:

2:

FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:

初始化mysql數據庫提示缺乏Data:dumper模塊解決方法
Data::Dumper
解決方法 :安裝autoconf庫
命令:yum-y install autoconf

安裝完autoconf庫,再運行
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/

3: 啓動時:Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)

沒有權限:

chown -R mysql.mysql /var/lib/mysql ##該命令僅爲示例,其中/data/mysql就是mysql配置文件中datadir的目錄 ##若爲空,則默認爲mysql安裝目錄下的data文件夾下

[Mysql-Cluster-7.5搭建數據庫集羣]

http://www.cnblogs.com/leohe/p/6729014.html

http://www.cnblogs.com/linkstar/p/6510713.html

http://blog.csdn.net/mlz_2/article/details/72312336

http://blog.csdn.net/z_102865/article/details/52162492

https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-install-windows-binary.html

相關文章
相關標籤/搜索