首页 > 数据库 > 其他综合 >

centos7中mysql数据库安装和配置

2017-04-05

centos7中mysql数据库安装和配置,工具和软件。

工具和软件

1. centos 7.x

2. mysql 5.6.35

mysql安装

[root@finder220 ~]# yum install mysql-server
Loaded plugins: fastestmirror, langpacks
base                                                                                            | 3.6 kB  00:00:00     
extras                                                                                          | 3.4 kB  00:00:00     
updates                                                                                         | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
No package mysql-server available.
Error: Nothing to do

出现如上的问题 是因为CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。

有2中解决方案

方案一: 安装 mariadb

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。

# yum install mariadb-server mariadb

mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
所以先启动数据库

# systemctl start mariadb
# mysql -u root -p  和使用mysql一样来用

方法二: 下载安装包 mysql-server

[root@finder220 ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@finder220 mytest]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@finder220 mytest]# yum install mysql-community-server

相关安装信息

Loaded plugins: fastestmirror, langpacks
Examining mysql-community-release-el7-5.noarch.rpm: mysql-community-release-el7-5.noarch
mysql-community-release-el7-5.noarch.rpm: does not update installed package.
Error: Nothing to do
[root@finder220 mytest]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
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     
(1/3): mysql-connectors-community/x86_64/primary_db                                             |  13 kB  00:00:00     
(2/3): mysql-tools-community/x86_64/primary_db                                                  |  32 kB  00:00:00     
(3/3): mysql56-community/x86_64/primary_db                                                      | 159 kB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.35-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.35-2.el7 for package: mysql-community-server-5.6.35-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.35-2.el7.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.35-2.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.35-2.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.35-2.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.35-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.35-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.35-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.35-2.el7               mysql56-community              59 M
Installing for dependencies:
 mysql-community-client              x86_64             5.6.35-2.el7               mysql56-community              19 M
 mysql-community-common              x86_64             5.6.35-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 (+8 Dependent packages)

Total download size: 82 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.35-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.6.35-2.el7.x86_64.rpm is not installed
(1/10): mysql-community-common-5.6.35-2.el7.x86_64.rpm                                          | 257 kB  00:00:01     
(2/10): mysql-community-libs-5.6.35-2.el7.x86_64.rpm                                            | 2.0 MB  00:00:00     
(3/10): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                                          |  32 kB  00:00:00     
(4/10): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                                           |  57 kB  00:00:00     
(5/10): perl-Net-Daemon-0.48-5.el7.noarch.rpm                                                   |  51 kB  00:00:00     
(6/10): perl-IO-Compress-2.061-2.el7.noarch.rpm                                                 | 260 kB  00:00:00     
(7/10): perl-PlRPC-0.2020-14.el7.noarch.rpm                                                     |  36 kB  00:00:00     
(8/10): perl-DBI-1.627-4.el7.x86_64.rpm                                                         | 802 kB  00:00:00     
(9/10): mysql-community-server-5.6.35-2.el7.x86_64.rpm                                          |  59 MB  00:00:22     
(10/10): mysql-community-client-5.6.35-2.el7 83% [=============================      ]  64 kB/s |  68 MB  00:03:43 ETA 
(10/10): mysql-community-client-5.6.35-2.el7 83% [=============================      ]  65 kB/s |  68 MB  00:03:34 ETA 
(10/10): mysql-community-client-5.6.35-2.el7 90% [===============================-   ]  88 kB/s |  74 MB  00:01:32 ETA 
(10/10): mysql-community-client-5.6.35-2.el7 92% [================================-  ]  35 kB/s |  76 MB  00:02:51 ETA 
(10/10): mysql-community-client-5.6.35-2.el7.x86_64.rpm                                         |  19 MB  00:06:50     
-----------------------------------------------------------------------------------------------------------------------
Total                                                                                  204 kB/s |  82 MB  00:06:50     
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    : mysql-community-release-el7-5.noarch (installed)
 From       : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: 

Didn't install any keys


安装成功后重启mysql服务。

我们查看3306 端口是否打开

[root@finder221 ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2292/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1182/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2422/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      3718/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      2292/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1182/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      2422/master

打开成功了。

初次安装mysql,root账户没有密码。

[root@finder221 ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@finder221 ~]# service mysql restart
Redirecting to /bin/systemctl restart  mysql.service
[root@finder221 ~]# 
[root@finder221 ~]# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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 database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> 

设置密码登陆

mysql> set password for 'root'@'localhost' =password('password$1');
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@finder221 ~]# mysql 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@finder221 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> 

至此 mysql安装完成

其他:

允许 root远程登录

grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';
flush privileges;

测试

# mysql -uroot -p'password$1' -h192.168.1.221

相关文章
最新文章
热点推荐