引言
因PL/SQL
不能连接MySQL
,因此附带安装说明图解吧。
CentOS 7.4.1708 系统下安装MySQL 5.7
一、官方安装文档
A Quick Guide to Using the MySQL Yum Repository
MySQL 5.7 Reference Manual
此处 MySQL Yum Repository为官方Yum
仓库。
二、下载 Mysql yum包
野鸡仓库:https://repo.mysql.com/yum/
上图就是MySQL的野鸡yum 仓库
三、实操
Centos 7
默认安装数据库是Mariadb
, 但是多数人都选择用 Mysql
,只是默认CentOS7
中的yum源
中好像是没有Mysql
的。
首先,Centos7
已经不支持MySQL
,因为【收费了】你懂得。所以内部集成了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
就是安装\卸载时不检查依赖关系,忽略软件包的依赖关系。比如你这个rpm
需要A
,但是你没装A
,这样你的包就装不上,用了--nodeps
你就能装上了。
--force
就是强制安装,比如你装过这个rpm
的版本1,如果你想装这个rpm
的版本2,就需要用--force
强制安装
卸载MySQL
假使曾经安装过旧有的MySQL 5.6
,现在需要安装MySQL 5.7
的情况下,就需要先卸载MySQL
老版本。
1.卸载
先停掉mysql
进程
pkill -9 mysqld
查看已经安装过的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
依次卸载 直到没有
这样就卸载好了~
安装MySQL
Centos7默认数据库是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 "
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!
这样装环境变量配置都不用你管,装上直接启动就行。安装路径是默认的。
默认配置文件路径:
- 配置文件:/etc/my.cnf
- 日志文件:/var/log/mysqld.log
- 服务启动脚本:/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服务
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 为了安全密码 必须包含 数字字母符号
踩过的坑啊,设置了好几次。
#重置root用户的密码
alter user 'root'@'localhost' identified by 'Root!!2018';
Navicat连接阿里云ECS服务器上的MySQL数据库
1、进入linux连接数据库并输入密码:
mysql -u root -p
2、输入以下命令进行授权:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '这里写自己数据库的密码' WITH GRANT OPTION;
3、刷新权限:
FLUSH PRIVILEGES;
4、但是添加了权限之后,还是连接不上数据库。必须给服务器的安全组设置端口放行规则
5、进入Navicat,新建连接,在“常规”选项卡中输入开放权限时的信息,用户名:root;密码:123456
有关MySql权限的其他设置 (拓展)
- (1)设置访问单个数据库权限
mysql>grant all privileges on test.* to 'root'@'%';
设置用户名为root,密码为空,可访问数据库test
(2)设置访问全部数据库权限
mysql>grant all privileges on *.* to 'root'@'%';
设置用户名为root,密码为空,可访问所有数据库*
(3)设置指定用户名访问权限
mysql>grant all privileges on *.* to 'root'@'%';
设置指定用户名为root,密码为空,可访问所有数据库*
(4)设置密码访问权限
mysql>grant all privileges on *.* to 'root'@'%' IDENTIFIED BY '123456';
设置指定用户名为root,密码为123456,可访问所有数据库*
(5)设置指定可访问主机权限
mysql>grant all privileges on *.* to 'root'@'11.1.1.1';
设置指定用户名为root,可访问所有数据库*,只有11.1.1.1这台机器有权限访问
异常错误:
我一开始使用的navicat版本为11.0.9,出现了如下错误:
SSH: expected key exchange group packer from server
翻阅各种别人的解决方案,尝试换了navicat的版本至11.2.7,问题就迎刃而解了!
现分享Navicat的下载链接:
https://pan.baidu.com/s/1WBYcgC7-ee9nbquMFJe4Dw 密码:pz5z
d