1.linux系统 mysql安装
1.1.使用yum list | grep mysql 来查找yum源中是否有mysql
[root@VM_47_56_centos ~]# yum list | grep mysql
akonadi-mysql.x 86_64 1.9 .2 -4. el7 base
apr-util-mysql.x 86_64 1.5 .2 -6. el7 base
mysql-proxy.x 86_64 0.8 .5 -2. el7 epel
mysql-proxy-devel.x 86_64 0.8 .5 -2. el7 epel
mysql-router.x 86_64 2.0 .2 -1. el7 mysql-tools-community
mysql-router-debuginfo.x 86_64 2.0 .2 -1. el7 mysql-tools-community
mysql-utilities.noarch 1.5 .6 -1. el7 mysql-tools-community
mysql-utilities-extra.noarch 1.5 .6 -1. el7 mysql-tools
mysqlreport.noarch 3.5 -11. el7 epel
mysqltuner.noarch 1.2 .0 -7. el7 epel
省略部分内容。。。。
[root@VM_47_56_centos ~]#
1.2.下载mysql的repo源
$ wget http:
$ sudo rpm -ivh mysql-community-release-el7-5. noarch.rpm
安装这个包后,会获得两个mysql的yum repo源:
/etc/yum.repos.d/mysql-community.repo和
/etc/yum.repos.d/mysql-community-source.repo。
1.4.安装mysql
$ sudo yum install mysql-server
[root@izwz 91h49n3mj8r232gqwez opt]# sudo yum install mysql-server
Loaded plugins: fastestmirror
base | 3.6 kB 00 :00 :00
epel | 3.2 kB 00 :00 :00
extras | 3.4 kB 00 :00 :00
mysql-connectors-community | 2.5 kB 00 :00 :00
mysql-tools-community | 2.5 kB 00 :00 :00
mysql56-community | 2.5 kB 00 :00 :00
updates | 3.4 kB 00 :00 :00
(1 /7 ): epel/x86_64/updateinfo | 939 kB 00 :00 :00
(2 /7 ): extras/7 /x86_64/primary_db | 187 kB 00 :00 :00
(3 /7 ): epel/x86_64/primary | 3.6 MB 00 :00 :00
(4 /7 ): updates/7 /x86_64/primary_db | 5.2 MB 00 :00 :00
(5 /7 ): mysql-tools-community/x86_64/primary_db | 45 kB 00 :00 :00
(6 /7 ): mysql-connectors-community/x86_64/primary_db | 26 kB 00 :00 :00
(7 /7 ): mysql56-community/x86_64/primary_db | 197 kB 00 :00 :00
Loading mirror speeds from cached hostfile
epel 12671 /12671
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0 :5.6 .41 -2. el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64 ) = 5.6 .41 -2. el7 for package : mysql-community-server-5.6 .41 -2. el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64 ) >= 5.6 .10 for package : mysql-community-server-5.6 .41 -2. el7.x86_64
--> Processing Dependency: perl(DBI) for package : mysql-community-server-5.6 .41 -2. el7.x86_64
--> Processing Dependency: libaio.so.1 (LIBAIO_0.4 )(64 bit) for package : mysql-community-server-5.6 .41 -2. el7.x86_64
--> Processing Dependency: libaio.so.1 (LIBAIO_0.1 )(64 bit) for package : mysql-community-server-5.6 .41 -2. el7.x86_64
--> Processing Dependency: libaio.so.1 ()(64 bit) for package : mysql-community-server-5.6 .41 -2. el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0 :0.3 .109 -13. el7 will be installed
---> Package mysql-community-client.x86_64 0 :5.6 .41 -2. el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64 ) >= 5.6 .10 for package : mysql-community-client-5.6 .41 -2. el7.x86_64
---> Package mysql-community-common.x86_64 0 :5.6 .41 -2. el7 will be installed
---> Package perl-DBI.x86_64 0 :1.627 -4. el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package : perl-DBI-1.627 -4. el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package : perl-DBI-1.627 -4. el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1 :5.5 .52 -1. el7 will be obsoleted
---> Package mysql-community-libs.x86_64 0 :5.6 .41 -2. el7 will be obsoleting
---> Package perl-PlRPC.noarch 0 :0.2020 -14. el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package : perl-PlRPC-0.2020 -14. el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package : perl-PlRPC-0.2020 -14. el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package : perl-PlRPC-0.2020 -14. el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package : perl-PlRPC-0.2020 -14. el7.noarch
--> Running transaction check
---> Package perl-IO-Compress.noarch 0 :2.061 -2. el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package : perl-IO-Compress-2.061 -2. el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package : perl-IO-Compress-2.061 -2. el7.noarch
---> Package perl-Net-Daemon.noarch 0 :0.48 -5. el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0 :2.061 -3. el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1 :2.061 -4. el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================================================
Installing:
mysql-community-libs x86_64 5.6 .41 -2. el7 mysql56-community 2.0 M
replacing mariadb-libs.x86_64 1 :5.5 .52 -1. el7
mysql-community-server x86_64 5.6 .41 -2. el7 mysql56-community 59 M
Installing for dependencies:
libaio x86_64 0.3 .109 -13. el7 base 24 k
mysql-community-client x86_64 5.6 .41 -2. el7 mysql56-community 19 M
mysql-community-common x86_64 5.6 .41 -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-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
Transaction Summary
===============================================================================================================================================================================================
Install 2 Packages (+9 Dependent packages)
Total download size: 82 M
Is this ok [y/d/N]: y
Downloading packages:
(1 /11 ): libaio-0.3 .109 -13. el7.x86_64.rpm | 24 kB 00 :00 :00
warning: /var/cache/yum/x86_64/7 /mysql56-community/packages/mysql-community-common-5.6 .41 -2. el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1 f5: NOKEY43 kB/s | 138 kB 00 :09 :48 ETA
Public key for mysql-community-common-5.6 .41 -2. el7.x86_64.rpm is not installed
(2 /11 ): mysql-community-common-5.6 .41 -2. el7.x86_64.rpm | 257 kB 00 :00 :00
(3 /11 ): mysql-community-libs-5.6 .41 -2. el7.x86_64.rpm | 2.0 MB 00 :00 :01
(4 /11 ): perl-Compress-Raw-Bzip2-2.061 -3. el7.x86_64.rpm | 32 kB 00 :00 :00
(5 /11 ): perl-Compress-Raw-Zlib-2.061 -4. el7.x86_64.rpm | 57 kB 00 :00 :00
(6 /11 ): perl-DBI-1.627 -4. el7.x86_64.rpm | 802 kB 00 :00 :00
(7 /11 ): perl-Net-Daemon-0.48 -5. el7.noarch.rpm | 51 kB 00 :00 :00
(8 /11 ): perl-PlRPC-0.2020 -14. el7.noarch.rpm | 36 kB 00 :00 :00
(9 /11 ): perl-IO-Compress-2.061 -2. el7.noarch.rpm | 260 kB 00 :00 :00
(10 /11 ): mysql-community-client-5.6 .41 -2. el7.x86_64.rpm | 19 MB 00 :00 :11
(11 /11 ): mysql-community-server-5.6 .41 -2. el7.x86_64.rpm | 59 MB 00 :00 :35
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.2 MB/s | 82 MB 00 :00 :37
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5 :
Userid : "MySQL Release Engineering <[email protected] >"
Fingerprint: a4a9 4068 76 fc bd3c 4567 70 c8 8 c71 8 d3b 5072 e1f5
Package : mysql-community-release-el7-5. noarch (installed)
From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.6 .41 -2. el7.x86_64 1 /12
Installing : mysql-community-libs-5.6 .41 -2. el7.x86_64 2 /12
Installing : mysql-community-client-5.6 .41 -2. el7.x86_64 3 /12
Installing : libaio-0.3 .109 -13. el7.x86_64 4 /12
Installing : perl-Net-Daemon-0.48 -5. el7.noarch 5 /12
Installing : 1 :perl-Compress-Raw-Zlib-2.061 -4. el7.x86_64 6 /12
Installing : perl-Compress-Raw-Bzip2-2.061 -3. el7.x86_64 7 /12
Installing : perl-IO-Compress-2.061 -2. el7.noarch 8 /12
Installing : perl-PlRPC-0.2020 -14. el7.noarch 9 /12
Installing : perl-DBI-1.627 -4. el7.x86_64 10 /12
Installing : mysql-community-server-5.6 .41 -2. el7.x86_64 11 /12
Erasing : 1 :mariadb-libs-5.5 .52 -1. el7.x86_64 12 /12
Verifying : mysql-community-server-5.6 .41 -2. el7.x86_64 1 /12
Verifying : perl-Compress-Raw-Bzip2-2.061 -3. el7.x86_64 2 /12
Verifying : mysql-community-client-5.6 .41 -2. el7.x86_64 3 /12
Verifying : mysql-community-libs-5.6 .41 -2. el7.x86_64 4 /12
Verifying : mysql-community-common-5.6 .41 -2. el7.x86_64 5 /12
Verifying : perl-IO-Compress-2.061 -2. el7.noarch 6 /12
Verifying : 1 :perl-Compress-Raw-Zlib-2.061 -4. el7.x86_64 7 /12
Verifying : perl-Net-Daemon-0.48 -5. el7.noarch 8 /12
Verifying : perl-DBI-1.627 -4. el7.x86_64 9 /12
Verifying : libaio-0.3 .109 -13. el7.x86_64 10 /12
Verifying : perl-PlRPC-0.2020 -14. el7.noarch 11 /12
Verifying : 1 :mariadb-libs-5.5 .52 -1. el7.x86_64 12 /12
Installed:
mysql-community-libs.x86_64 0 :5.6 .41 -2. el7 mysql-community-server.x86_64 0 :5.6 .41 -2. el7
Dependency Installed:
libaio.x86_64 0 :0.3 .109 -13. el7 mysql-community-client.x86_64 0 :5.6 .41 -2. el7 mysql-community-common.x86_64 0 :5.6 .41 -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-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
Replaced:
mariadb-libs.x86_64 1 :5.5 .52 -1. el7
Complete!
下边的安装和其他安装一样,
根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。
1.5.重置密码
1.5.1.登录
$ mysql -u root
登录时有可能报这样的错:
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2 ),
原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
$ sudo chown -R mysql:mysql /var/lib/mysql #这里的mysql是用户名(需要设置用户组合用户)
然后重启
$ service mysqld restart
1.5.2.接下来登录重置密码:
$ mysql -u root
mysql > use mysql;
mysql > update user set password=password('xu827928' ) where user='root' ;
mysql > exit;
1.6.开放3306端口(可以不用设置)
sudo systemctl stop firewalld.service
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
这样从其它客户机也可以连接上mysql服务了。
1.7.修改权限可以使其他机器登录:
[root@izwz 91h49n3mj8r232gqwez ~]# mysql -h localhost -u root
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' WITH GRANT OPTION
mysql>FLUSH PRIVILEGES
mysql>EXIT