鼓捣了一下午都没有在CentOS下安装成功MySql,
正巧群里的基友推荐了一种简单的安装方法,特意分享一下
首先我们先安装带有可用的mysql5系列社区版资源的rpm包
[root@localhost mysql]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
获取http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-release-el7-5 ################################# [100%]
接着查看当前可用的mysql安装资源
[root@localhost mysql]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 42
mysql-tools-community/x86_64 MySQL Tools Community 55
mysql56-community/x86_64 MySQL 5.6 Community Server 361
一般来说,这里只需要安装mysql-server跟mysql-client
这个时候我们就可以直接使用yum的方式安装MySQL了
[root@localhost mysql]# yum -y install mysql-community-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.6.38-2.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.6.38-2.el7,它被软件包 mysql-community-server-5.6.38-2.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.6.10,它被软件包 mysql-community-server-5.6.38-2.el7.x86_64 需要
--> 正在处理依赖关系 perl(Data::Dumper),它被软件包 mysql-community-server-5.6.38-2.el7.x86_64 需要
--> 正在处理依赖关系 perl(DBI),它被软件包 mysql-community-server-5.6.38-2.el7.x86_64 需要
--> 正在检查事务
---> 软件包 MySQL-client.x86_64.0.5.6.36-1.el7 将被 取代
---> 软件包 mysql-community-client.x86_64.0.5.6.38-2.el7 将被 舍弃
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.6.10,它被软件包 mysql-community-client-5.6.38-2.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.6.38-2.el7 将被 安装
---> 软件包 perl-DBI.x86_64.0.1.627-4.el7 将被 安装
--> 正在处理依赖关系 perl(RPC::PlServer) >= 0.2001,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在处理依赖关系 perl(RPC::PlClient) >= 0.2000,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
---> 软件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.56-2.el7 将被 取代
---> 软件包 mysql-community-libs.x86_64.0.5.6.38-2.el7 将被 舍弃
---> 软件包 perl-PlRPC.noarch.0.0.2020-14.el7 将被 安装
--> 正在处理依赖关系 perl(Net::Daemon) >= 0.13,它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Test),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Log),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Zlib),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在检查事务
---> 软件包 perl-IO-Compress.noarch.0.2.061-2.el7 将被 安装
--> 正在处理依赖关系 perl(Compress::Raw::Zlib) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Raw::Bzip2) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
---> 软件包 perl-Net-Daemon.noarch.0.0.48-5.el7 将被 安装
--> 正在检查事务
---> 软件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 将被 安装
---> 软件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==========================================================================================================================================================================================
Package 架构 版本 源 大小
==========================================================================================================================================================================================
正在安装:
mysql-community-client x86_64 5.6.38-2.el7 mysql56-community 19 M
替换 MySQL-client.x86_64 5.6.36-1.el7
mysql-community-libs x86_64 5.6.38-2.el7 mysql56-community 2.0 M
替换 mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.6.38-2.el7 mysql56-community 59 M
为依赖而安装:
mysql-community-common x86_64 5.6.38-2.el7 mysql56-community 257 k
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-Data-Dumper x86_64 2.145-3.el7 base 47 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
事务概要
==========================================================================================================================================================================================
安装 3 软件包 (+8 依赖软件包)
总下载量:82 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.38-2.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY 0.0 B/s | 0 B --:--:-- ETA
mysql-community-common-5.6.38-2.el7.x86_64.rpm 的公钥尚未安装
(1/11): mysql-community-common-5.6.38-2.el7.x86_64.rpm | 257 kB 00:00:00
(2/11): mysql-community-libs-5.6.38-2.el7.x86_64.rpm | 2.0 MB 00:00:00
警告:/var/cache/yum/x86_64/7/base/packages/perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY ] 3.6 MB/s | 9.2 MB 00:00:20 ETA
perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm 的公钥尚未安装
(3/11): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00
(4/11): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00
(5/11): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00
(6/11): perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:00:00
(7/11): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00
(8/11): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:00
(9/11): mysql-community-client-5.6.38-2.el7.x86_64.rpm | 19 MB 00:00:04
(10/11): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:03
(11/11): mysql-community-server-5.6.38-2.el7.x86_64.rpm | 59 MB 00:00:09
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 7.4 MB/s | 82 MB 00:00:11
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
软件包 : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
从 file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key
软件包 : mysql-community-release-el7-5.noarch (installed)
来自 : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql-community-common-5.6.38-2.el7.x86_64 1/13
正在安装 : perl-Data-Dumper-2.145-3.el7.x86_64 2/13
正在安装 : mysql-community-libs-5.6.38-2.el7.x86_64 3/13
正在安装 : mysql-community-client-5.6.38-2.el7.x86_64 4/13
正在安装 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 5/13
正在安装 : perl-Net-Daemon-0.48-5.el7.noarch 6/13
正在安装 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 7/13
正在安装 : perl-IO-Compress-2.061-2.el7.noarch 8/13
正在安装 : perl-PlRPC-0.2020-14.el7.noarch 9/13
正在安装 : perl-DBI-1.627-4.el7.x86_64 10/13
正在安装 : mysql-community-server-5.6.38-2.el7.x86_64 11/13
正在删除 : 1:mariadb-libs-5.5.56-2.el7.x86_64 12/13
正在删除 : MySQL-client-5.6.36-1.el7.x86_64 13/13
验证中 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/13
验证中 : perl-Net-Daemon-0.48-5.el7.noarch 2/13
验证中 : perl-Data-Dumper-2.145-3.el7.x86_64 3/13
验证中 : perl-PlRPC-0.2020-14.el7.noarch 4/13
验证中 : mysql-community-client-5.6.38-2.el7.x86_64 5/13
验证中 : mysql-community-server-5.6.38-2.el7.x86_64 6/13
验证中 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 7/13
验证中 : mysql-community-common-5.6.38-2.el7.x86_64 8/13
验证中 : mysql-community-libs-5.6.38-2.el7.x86_64 9/13
验证中 : perl-DBI-1.627-4.el7.x86_64 10/13
验证中 : perl-IO-Compress-2.061-2.el7.noarch 11/13
验证中 : MySQL-client-5.6.36-1.el7.x86_64 12/13
验证中 : 1:mariadb-libs-5.5.56-2.el7.x86_64 13/13
已安装:
mysql-community-client.x86_64 0:5.6.38-2.el7 mysql-community-libs.x86_64 0:5.6.38-2.el7 mysql-community-server.x86_64 0:5.6.38-2.el7
作为依赖被安装:
mysql-community-common.x86_64 0:5.6.38-2.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7
替代:
MySQL-client.x86_64 0:5.6.36-1.el7 mariadb-libs.x86_64 1:5.5.56-2.el7
完毕!
巴拉巴拉一大堆,做到这里就完成一大半了
之后是加入开机自启
[root@localhost mysql]# systemctl enable mysqld
开启MySql服务
[root@localhost mysql]# systemctl start mysqld
设置用户密码
[root@localhost mysql]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] y ###############是否设置root用户的密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y ###############是否删除匿名用户
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n ###############是否禁止root远程登陆
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y ###############是否删除test数据库
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y ###############是否刷新权限
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
重置密码 密码默认初始 是空格 回车就行了
修改数据库的字符集
输入用户密码,进入数据库
[root@localhost mysql]# mysql -u root -h 127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
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> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
可以看到character_set_database和character_set_server的默认字符集还是latin1。
修改my.cnf文件中的字符集键值(注意配置的字段细节)
按“i”键进入编辑模式,将“character-set-server=utf8”追加入到【mysqld】中
[root@localhost ~]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[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
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
按ESC键退出编辑模式,CTRL + Z 退出
输入”sudo systemctl restart mysqld”重启MySql服务
回来我们重新查看一下数据库的字符集
[root@localhost ~]# mysql -u root -h 127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
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> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> exit;
Bye
一切搞定
解决远程连接mysql错误1130代码
待续。。。