centos7.2安裝mysql5.6.38

在網上找了一下資料,發現都不是很適合,所以自己結合各個版本的方法總結了一下。
一、下載mysql
11
選擇要下載的版本
22

33

44

55
注意:centos內核基於Red Hat,所以下載的時候需要下載Red Hat版本
二、安裝mysql
1)查看系統是否已安裝mysql
[root@jdu4e00u53f7 mysql]# rpm -qa | grep -i mysql
MySQL-client-5.6.38-1.el7.x86_64
MySQL-server-5.6.38-1.el7.x86_64
MySQL-devel-5.6.38-1.el7.x86_64
2)卸載
[root@jdu4e00u53f7 mysql]# rpm -e MySQL-client-5.6.38-1.el7.x86_64
[root@jdu4e00u53f7 mysql]# rpm -e MySQL-server-5.6.38-1.el7.x86_64
[root@jdu4e00u53f7 mysql]# rpm -e MySQL-devel-5.6.38-1.el7.x86_64
3)刪除服務
[root@jdu4e00u53f7 mysql]# chkconfig --list | grep -i mysql
[root@jdu4e00u53f7 mysql]# chkconfig --del mysql
4)刪除mysql分散的文件夾
查找
[root@jdu4e00u53f7 /]# find / -name *mysql*
刪除
rm -rf /use/lib/mysql...
5) 上傳,解壓
解壓 tar -xvf MySQL-5.6.38-1.el7.x86_64.rpm-bundle.tar (注意,是-xvf不是-zxvf)
-rw-r--r-- 1 root root 243793920 Nov 17 09:57 MySQL-5.6.38-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415 20322752 Sep 14 19:00 MySQL-client-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 3535660 Sep 14 19:00 MySQL-devel-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 93055580 Sep 14 19:01 MySQL-embedded-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 62422764 Sep 14 19:01 MySQL-server-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2105180 Sep 14 19:01 MySQL-shared-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2299632 Sep 14 19:01 MySQL-shared-compat-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 60042116 Sep 14 19:01 MySQL-test-5.6.38-1.el7.x86_64.rpm
6)卸載MariaDB
[root@jdu4e00u53f7 mysql] rpm -qa | grep mariadb
mariadb-libs-5.5.41-2.el7_0.x86_64
[root@jdu4e00u53f7 mysql] rpm -e --nodeps mariadb-libs-5.5.41-2.el7_0.x86_64
7)安裝mysql
按順序安裝
rpm -ivh MySQL-client-5.6.38-1.el7.x86_64.rpm
rpm -ivh MySQL-devel-5.6.38-1.el7.x86_64.rpm
rpm -ivh MySQL-server-5.6.38-1.el7.x86_64.rpm
8)啓動mysql
[root@jdu4e00u53f7 mysql]# service mysql status
SUCCESS! MySQL running (17886)
[root@jdu4e00u53f7 mysql]# netstat -ano | grep 3306
tcp6 0 0 :::3306 :::* LISTEN off (0.00/0/0)
三、修改密碼
[root@jdu4e00u53f7 mysql]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
連接mysql的時候發現沒有初始密碼,不能連接
1)停止服務
[root@jdu4e00u53f7 ~]# service mysql stop
Shutting down MySQL.. SUCCESS!
2)繞過密碼登錄
[root@jdu4e00u53f7 ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 18369
[root@jdu4e00u53f7 ~]# 171117 10:54:38 mysqld_safe Logging to '/var/lib/mysql/jdu4e00u53f7.err'.
171117 10:54:38 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@jdu4e00u53f7 ~]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>
3)登錄成功之後修改密碼
a)切換數據庫
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

b)查詢用戶
mysql> select Host,User,Password from user;
+--------------+------+-------------------------------------------+
| Host | User | Password |
+--------------+------+-------------------------------------------+
| localhost | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
| XXXXX | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
| 127.0.0.1 | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
| ::1 | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
+--------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
c)修改密碼
mysql> UPDATE user SET password=password("root") WHERE user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql>
d)退出、重新登錄
mysql> quit;
Bye
[root@jdu4e00u53f7 ~]# mysql -u root -proot
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 4
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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@jdu4e00u53f7 mysql]# chkconfig --list mysql

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@jdu4e00u53f7 mysql]#

如果不是開機自啓動,使用開啓MySQL服務自動開啓命令:
chkconfig mysqld on
chkconfig mysql on


mysql集合重要目錄
/var/lib/mysql 數據庫文件
/usr/share/mysql 命令及配置文件
/usr/bin mysqladmin、mysqldump等命令

五、設置數據庫允許其它計算機訪問
a)打開數據庫下邊的mysql庫
b)執行sql
INSERT INTO `user` (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`) VALUES ('%', 'root', '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0', 'mysql_native_password', '', 'N');
c)刷新權限
flush privileges;




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章