引言
因PL/SQL
不能連接MySQL
,因此附帶安裝說明圖解吧该溯。
CentOS 7.4.1708 系統(tǒng)下安裝MySQL 5.7
一、官方安裝文檔
此處 MySQL Yum Repository為官方Yum
倉庫虱饿。
二愉阎、下載 Mysql yum包
上圖就是MySQL的野雞yum 倉庫
三桦踊、實操
Centos 7
默認安裝數(shù)據(jù)庫是Mariadb
, 但是多數(shù)人都選擇用 Mysql
椅野,只是默認CentOS7
中的yum源
中好像是沒有Mysql
的。
首先籍胯,Centos7
已經(jīng)不支持MySQL
竟闪,因為【收費了】你懂得。所以內(nèi)部集成了Mariadb
杖狼,而安裝Mysql
的話會和Mariadb
的文件沖突炼蛤,所以需要先卸載掉Mariadb
。
以下為卸載Mariadb
蝶涩,安裝Mysql
的步驟理朋。
卸載Mariadb
- 列出所有被安裝的
rpm package
[root@OzanZone /]# rpm -qa|grep maria
mariadb-libs-5.5.56-2.el7.x86_64
- 卸載
[root@OzanZone /]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
錯誤:依賴檢測失敗:
libmysqlclient.so.18()(64bit)
被 (已安裝的)postfix-2:2.10.1-6.el7.x86_64
需要
libmysqlclient.so.18(libmysqlclient_18)(64bit)
被 (已安裝的)postfix-2:2.10.1-6.el7.x86_64
需要
- 強制卸載绿聘,因為沒有加
--nodeps
[root@OzanZone /]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
--nodeps
就是安裝\卸載時不檢查依賴關(guān)系嗽上,忽略軟件包的依賴關(guān)系。比如你這個rpm
需要A
熄攘,但是你沒裝A
兽愤,這樣你的包就裝不上,用了--nodeps
你就能裝上了挪圾。
--force
就是強制安裝浅萧,比如你裝過這個rpm
的版本1,如果你想裝這個rpm
的版本2哲思,就需要用--force
強制安裝
卸載MySQL
假使曾經(jīng)安裝過舊有的MySQL 5.6
洼畅,現(xiàn)在需要安裝MySQL 5.7
的情況下,就需要先卸載MySQL
老版本棚赔。
1.卸載
先停掉mysql
進程
pkill -9 mysqld
查看已經(jīng)安裝過的mysql
的rpm
包
rpm -qa|grep -i mysql
用命令 yum -y remove
刪除
yum -y remove mysql-community-client-5.6.38-2.el7.x86_64
卸載不掉的用rpm -ev
依次卸載 直到?jīng)]有
這樣就卸載好了~
安裝MySQL
Centos7默認數(shù)據(jù)庫是mariadb, 但是 好多用的都是mysql 土思,但是CentOS7的yum源中默認好像是沒有mysql的。
1忆嗜、配置YUM源
下載mysql的repo源,這個安裝的mysql5.7.20
這源下載的是最新的版本
[root@OzanZone /]# cd usr/local/src/
[root@OzanZone src]# wget http://repo.mysql.com/mysql57-community-release-el7.rpm
--2018-05-19 14:03:11-- http://repo.mysql.com/mysql57-community-release-el7.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.211.13.175
Connecting to repo.mysql.com (repo.mysql.com)|23.211.13.175|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7.rpm’
100%[====================================================================>] 25,680 --.-K/s in 0.05s
2018-05-19 14:03:12 (462 KB/s) - ‘mysql57-community-release-el7.rpm’ saved [25680/25680]
[root@OzanZone src]# rpm -ivh mysql57-community-release-el7.rpm
warning: mysql57-community-release-el7.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-11 ################################# [100%]
[root@OzanZone src]# yum -y install mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql57-community | 2.5 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 20 kB 00:00:00
(2/3): mysql-tools-community/x86_64/primary_db | 41 kB 00:00:00
(3/3): mysql57-community/x86_64/primary_db | 144 kB 00:00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.22-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.22-1.el7 for package: mysql-community-server-5.7.22-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.22-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.22-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.22-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.22-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.22-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================
Package Arch Version Repository Size
==============================================================================================================
Installing:
mysql-community-server x86_64 5.7.22-1.el7 mysql57-community 165 M
Installing for dependencies:
mysql-community-client x86_64 5.7.22-1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.22-1.el7 mysql57-community 274 k
mysql-community-libs x86_64 5.7.22-1.el7 mysql57-community 2.1 M
Transaction Summary
==============================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 191 M
Installed size: 862 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.22-1.el7.x86_64.rpm is not installed
(1/4): mysql-community-common-5.7.22-1.el7.x86_64.rpm | 274 kB 00:00:00
(2/4): mysql-community-libs-5.7.22-1.el7.x86_64.rpm | 2.1 MB 00:00:00
(3/4): mysql-community-client-5.7.22-1.el7.x86_64.rpm | 24 MB 00:00:01
(4/4): mysql-community-server-5.7.22-1.el7.x86_64.rpm | 165 MB 00:00:20
--------------------------------------------------------------------------------------------------------------
Total 9.2 MB/s | 191 MB 00:00:20
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql57-community-release-el7-11.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
Installing : mysql-community-common-5.7.22-1.el7.x86_64 1/4
Installing : mysql-community-libs-5.7.22-1.el7.x86_64 2/4
Installing : mysql-community-client-5.7.22-1.el7.x86_64 3/4
Installing : mysql-community-server-5.7.22-1.el7.x86_64 4/4
Verifying : mysql-community-client-5.7.22-1.el7.x86_64 1/4
Verifying : mysql-community-libs-5.7.22-1.el7.x86_64 2/4
Verifying : mysql-community-common-5.7.22-1.el7.x86_64 3/4
Verifying : mysql-community-server-5.7.22-1.el7.x86_64 4/4
Installed:
mysql-community-server.x86_64 0:5.7.22-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.22-1.el7 mysql-community-common.x86_64 0:5.7.22-1.el7
mysql-community-libs.x86_64 0:5.7.22-1.el7
Complete!
這樣裝環(huán)境變量配置都不用你管崎岂,裝上直接啟動就行捆毫。安裝路徑是默認的。
默認配置文件路徑:
- 配置文件:/etc/my.cnf
- 日志文件:/var/log/mysqld.log
- 服務(wù)啟動腳本:/usr/lib/systemd/system/mysqld.service
- socket文件:/var/lib/mysql/mysql.sock
配置 my.cnf
vim /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
#server_id = 1
#expire_logs_days = 3
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
不過安裝完成后冲甘,密碼為隨機密碼绩卤,需要重置密碼途样。
啟動mysql服務(wù)
systemctl start mysqld
重置密碼:
[root@OzanZone mysqld]# systemctl start mysqld
[root@OzanZone mysqld]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@OzanZone mysqld]# grep "password" /var/log/mysqld.log
2018-05-19T06:23:24.753875Z 1 [Note] A temporary password is generated for root@localhost: zY8Jg+Dy:a6L
2018-05-19T06:24:18.691536Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
grep "password" /var/log/mysqld.log
查出mysql 5.7的初始密碼
然后重新登陸。
接下來重置密碼:5.7.20 為了安全密碼 必須包含 數(shù)字字母符號
踩過的坑啊濒憋,設(shè)置了好幾次何暇。
#重置root用戶的密碼
alter user 'root'@'localhost' identified by 'Root!!2018';
Navicat連接阿里云ECS服務(wù)器上的MySQL數(shù)據(jù)庫
1、進入linux連接數(shù)據(jù)庫并輸入密碼:
mysql -u root -p
2凛驮、輸入以下命令進行授權(quán):
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '這里寫自己數(shù)據(jù)庫的密碼' WITH GRANT OPTION;
3裆站、刷新權(quán)限:
FLUSH PRIVILEGES;
4、但是添加了權(quán)限之后黔夭,還是連接不上數(shù)據(jù)庫宏胯。必須給服務(wù)器的安全組設(shè)置端口放行規(guī)則
5、進入Navicat本姥,新建連接肩袍,在“常規(guī)”選項卡中輸入開放權(quán)限時的信息,用戶名:root婚惫;密碼:123456
有關(guān)MySql權(quán)限的其他設(shè)置 (拓展)
- (1)設(shè)置訪問單個數(shù)據(jù)庫權(quán)限
mysql>grant all privileges on test.* to 'root'@'%';
設(shè)置用戶名為root氛赐,密碼為空,可訪問數(shù)據(jù)庫test
(2)設(shè)置訪問全部數(shù)據(jù)庫權(quán)限
mysql>grant all privileges on *.* to 'root'@'%';
設(shè)置用戶名為root先舷,密碼為空艰管,可訪問所有數(shù)據(jù)庫*
(3)設(shè)置指定用戶名訪問權(quán)限
mysql>grant all privileges on *.* to 'root'@'%';
設(shè)置指定用戶名為root,密碼為空密浑,可訪問所有數(shù)據(jù)庫*
(4)設(shè)置密碼訪問權(quán)限
mysql>grant all privileges on *.* to 'root'@'%' IDENTIFIED BY '123456';
設(shè)置指定用戶名為root蛙婴,密碼為123456,可訪問所有數(shù)據(jù)庫*
(5)設(shè)置指定可訪問主機權(quán)限
mysql>grant all privileges on *.* to 'root'@'11.1.1.1';
設(shè)置指定用戶名為root尔破,可訪問所有數(shù)據(jù)庫*街图,只有11.1.1.1這臺機器有權(quán)限訪問
異常錯誤:
我一開始使用的navicat版本為11.0.9,出現(xiàn)了如下錯誤:
SSH: expected key exchange group packer from server
翻閱各種別人的解決方案懒构,嘗試換了navicat的版本至11.2.7餐济,問題就迎刃而解了!
現(xiàn)分享Navicat的下載鏈接:
https://pan.baidu.com/s/1WBYcgC7-ee9nbquMFJe4Dw 密碼:pz5z
d