Centos6快速安装mysql 5.6
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos6快速安装mysql 5.6相关的知识,希望对你有一定的参考价值。
一、检查系统是否安装其他版本的mysql数据
[[email protected] ~]# yum list installed | grep mysql
mysql-libs.x86_64 5.1.73-8.el6_8 @anaconda-CentOS-201703281317.x86_64/6.9
[[email protected] ~]# yum -y remove mysql-libs.x86_64
Loaded plugins: fastestmirror, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be erased
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-8.el6.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-8.el6.x86_64
--> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-8.el6.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.6.6-8.el6 will be erased
--> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-16.el6_8.2.x86_64
--> Running transaction check
---> Package cronie.x86_64 0:1.4.4-16.el6_8.2 will be erased
--> Processing Dependency: cronie = 1.4.4-16.el6_8.2 for package: cronie-anacron-1.4.4-16.el6_8.2.x86_64
--> Running transaction check
---> Package cronie-anacron.x86_64 0:1.4.4-16.el6_8.2 will be erased
--> Processing Dependency: /etc/cron.d for package: sysstat-9.0.4-33.el6.x86_64
--> Processing Dependency: /etc/cron.d for package: crontabs-1.10-33.el6.noarch
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package crontabs.noarch 0:1.10-33.el6 will be erased
---> Package sysstat.x86_64 0:9.0.4-33.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Removing:
mysql-libs x86_64 5.1.73-8.el6_8 @anaconda-CentOS-201703281317.x86_64/6.9 4.0 M
Removing for dependencies:
cronie x86_64 1.4.4-16.el6_8.2 @anaconda-CentOS-201703281317.x86_64/6.9 174 k
cronie-anacron x86_64 1.4.4-16.el6_8.2 @anaconda-CentOS-201703281317.x86_64/6.9 43 k
crontabs noarch 1.10-33.el6 @anaconda-CentOS-201703281317.x86_64/6.9 2.4 k
postfix x86_64 2:2.6.6-8.el6 @anaconda-CentOS-201703281317.x86_64/6.9 9.7 M
sysstat x86_64 9.0.4-33.el6 @anaconda-CentOS-201703281317.x86_64/6.9 826 k
Transaction Summary
==================================================================================================================================================================
Remove 6 Package(s)
Installed size: 15 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : sysstat-9.0.4-33.el6.x86_64 1/6
Erasing : cronie-1.4.4-16.el6_8.2.x86_64 2/6
Erasing : cronie-anacron-1.4.4-16.el6_8.2.x86_64 3/6
Erasing : crontabs-1.10-33.el6.noarch 4/6
Erasing : 2:postfix-2.6.6-8.el6.x86_64 5/6
Erasing : mysql-libs-5.1.73-8.el6_8.x86_64 6/6
Verifying : cronie-anacron-1.4.4-16.el6_8.2.x86_64 1/6
Verifying : cronie-1.4.4-16.el6_8.2.x86_64 2/6
Verifying : 2:postfix-2.6.6-8.el6.x86_64 3/6
Verifying : crontabs-1.10-33.el6.noarch 4/6
Verifying : sysstat-9.0.4-33.el6.x86_64 5/6
Verifying : mysql-libs-5.1.73-8.el6_8.x86_64 6/6
Removed:
mysql-libs.x86_64 0:5.1.73-8.el6_8
Dependency Removed:
cronie.x86_64 0:1.4.4-16.el6_8.2 cronie-anacron.x86_64 0:1.4.4-16.el6_8.2 crontabs.noarch 0:1.10-33.el6 postfix.x86_64 2:2.6.6-8.el6
sysstat.x86_64 0:9.0.4-33.el6
Complete!
二、安装及配置
[[email protected] ~]# yum list installed | grep mysql
[[email protected] ~]# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
--2018-04-23 01:23:56-- http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
Resolving repo.mysql.com... 23.50.239.110
Connecting to repo.mysql.com|23.50.239.110|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5824 (5.7K) [application/x-redhat-package-manager]
Saving to: “mysql-community-release-el6-5.noarch.rpm”
100%[========================================================================================================================>] 5,824 --.-K/s in 0s
2018-04-23 01:23:57 (190 MB/s) - “mysql-community-release-el6-5.noarch.rpm” saved [5824/5824]
[[email protected] ~]# ll
total 48
-rw-------. 1 root root 1139 Apr 19 23:22 anaconda-ks.cfg
-rw-r--r--. 1 root root 21736 Apr 19 23:22 install.log
-rw-r--r--. 1 root root 5890 Apr 19 23:20 install.log.syslog
-rw-r--r--. 1 root root 5824 Nov 12 2015 mysql-community-release-el6-5.noarch.rpm
[[email protected] ~]# rpm -ivh mysql-community-release-el6-5.noarch.rpm
Preparing... ########################################### [100%]
1:mysql-community-release########################################### [100%]
[[email protected] ~]# ll
total 48
-rw-------. 1 root root 1139 Apr 19 23:22 anaconda-ks.cfg
-rw-r--r--. 1 root root 21736 Apr 19 23:22 install.log
-rw-r--r--. 1 root root 5890 Apr 19 23:20 install.log.syslog
-rw-r--r--. 1 root root 5824 Nov 12 2015 mysql-community-release-el6-5.noarch.rpm
[[email protected] ~]# yum repolist all | grep mysql
mysql-connectors-community MySQL Connectors Community enabled: 49
mysql-connectors-community-source MySQL Connectors Community - So disabled
mysql-tools-community MySQL Tools Community enabled: 61
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - So disabled
mysql56-community MySQL 5.6 Community Server enabled: 434
mysql56-community-source MySQL 5.6 Community Server - So disabled
mysql57-community-dmr MySQL 5.7 Community Server Deve disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Deve disabled
安装MYSQL数据库
[[email protected] ~]# yum install mysql-community-server -y
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.40-2.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.40-2.el6 for package: mysql-community-server-5.6.40-2.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.40-2.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.40-2.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.40-2.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.40-2.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.6.40-2.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.40-2.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
mysql-community-server x86_64 5.6.40-2.el6 mysql56-community 55 M
Installing for dependencies:
mysql-community-client x86_64 5.6.40-2.el6 mysql56-community 18 M
mysql-community-common x86_64 5.6.40-2.el6 mysql56-community 308 k
mysql-community-libs x86_64 5.6.40-2.el6 mysql56-community 1.9 M
perl-DBI x86_64 1.609-4.el6 base 705 k
Transaction Summary
==================================================================================================================================================================
Install 5 Package(s)
Total download size: 75 M
Installed size: 337 M
Downloading Packages:
(1/5): mysql-community-client-5.6.40-2.el6.x86_64.rpm | 18 MB 00:33
(2/5): mysql-community-common-5.6.40-2.el6.x86_64.rpm | 308 kB 00:00
(3/5): mysql-community-libs-5.6.40-2.el6.x86_64.rpm | 1.9 MB 00:03
(4/5): mysql-community-server-5.6.40-2.el6.x86_64.rpm | 55 MB 02:55
(5/5): perl-DBI-1.609-4.el6.x86_64.rpm | 705 kB 00:01
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 358 kB/s | 75 MB 03:35
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering <[email protected]>
Package: mysql-community-release-el6-5.noarch (installed)
From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]>
Package: centos-release-6-9.el6.12.3.x86_64 (@anaconda-CentOS-201703281317.x86_64/6.9)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.6.40-2.el6.x86_64 1/5
Installing : mysql-community-libs-5.6.40-2.el6.x86_64 2/5
Installing : mysql-community-client-5.6.40-2.el6.x86_64 3/5
Installing : perl-DBI-1.609-4.el6.x86_64 4/5
Installing : mysql-community-server-5.6.40-2.el6.x86_64 5/5
Verifying : mysql-community-client-5.6.40-2.el6.x86_64 1/5
Verifying : mysql-community-common-5.6.40-2.el6.x86_64 2/5
Verifying : mysql-community-libs-5.6.40-2.el6.x86_64 3/5
Verifying : mysql-community-server-5.6.40-2.el6.x86_64 4/5
Verifying : perl-DBI-1.609-4.el6.x86_64 5/5
Installed:
mysql-community-server.x86_64 0:5.6.40-2.el6
Dependency Installed:
mysql-community-client.x86_64 0:5.6.40-2.el6 mysql-community-common.x86_64 0:5.6.40-2.el6 mysql-community-libs.x86_64 0:5.6.40-2.el6
perl-DBI.x86_64 0:1.609-4.el6
Complete!
设置为开机启动(2、3、4都是on代表开机自动启动)
[[email protected] ~]# chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[[email protected] ~]# chkconfig mysqld on
[[email protected] ~]# chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
三、设置远程root
启动mysql
# service mysqld start
设置root密码
# mysql_secure_installation
登陆root账号
# mysql -uroot -p
建立远程root用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你设置的密码' WITH GRANT OPTION;
mysql> flush privileges;
四、设置utf-8编码
查看mysql原本编码:
mysql> show variables like 'character%';
设置编码
# vi /etc/my.cnf
如下(少补):
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
sql_mode='NO_ENGINE_SUBSTITUTION'
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
重启mysql
# service mysqld restart
再次查看编码:
# mysql -uroot -p
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| 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)
以上是关于Centos6快速安装mysql 5.6的主要内容,如果未能解决你的问题,请参考以下文章
Centos6.5使用yum安装mysql——快速上手必备(转)