Centos7 安装mysql

版权声明:本文为徐代龙原创文章,未经徐代龙允许不得转载。福利网站:www.00reso.com https://blog.csdn.net/xudailong_blog/article/details/79945996

版权声明:

更多最全原创文章请访问:(https://blog.csdn.net/xudailong_blog)


最简方式,不到5分钟就可以成功安装mysql的教程

安装步骤

如果以下情况需要权限的话,尽量带上 sudo 命令

(1) 检查centos7上是否安装了自带的mysql

rpm -qa | grep mysql

情况一:如果有安装mysql,可以选择卸载:

rpm -e mysql  // 普通删除模式
rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

情况二:没有安装mysql,进行第二部,mysql的安装

(2)mysql的安装

yum install mysql
yum install mysql-server
yum install mysql-devel

接下来会有几个y让你选择,最后启动mysql

service mysqld start

或者

systemctl start mysql.service

这里你可能遇到一个问题:

Failed to start mysqld.service: Unit not found

找不到mysqld的服务,原因是 CentOS 7 版本,MySQL数据库已从默认的程序列表中移除,可以使用 mariadb 代替。

(3)centos7下进行mariadb-server的安装

(1) 安装mariadb-server

yum install -y mariadb-server

(2)启动mariadb-server

systemctl start mariadb.service

(3)添加到开启启动

 systemctl enable mariadb.service

这样我们就完成了mysql的安装,然后进行mysql的登陆,测试一下

(4) 验证mysql是否安装成功并进行登陆

(1)进行mysql安装成功与否的验证

mysqladmin --version

如果输出结果为:

mysqladmin Ver 9.0 Distrib 5.5.56-MariaDB, for Linux on x86_64

说明mysql安装成功了。

(2)mysql的登陆

一开始的mysql是没有密码的,也就是当你输入密码的时候直接按下enter键就可以了。

命令一:

mysql -u root -p

使用root账号进行登陆,这时会需要你提供密码,直接按下enter键就可以了。

命令二:

直接输入:

mysql

这时候再输入:

SHOW DATABASES;

然后你就会看到mysql数据库里面的DB库了。

到此,centos7上mysql的安装就已经安装完成了。

下面是全部安装的centos7上的输出,如果已经根据步骤安装成功了,就不用看下面的内容了。

[admin@iz2ze0pyv80iyyiundbb5oz ~]$ rpm -qa | grep mysql
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ yum install mysql
Loaded plugins: fastestmirror
You need to be root to perform this command.
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ sudo yum install mysql
[sudo] password for admin: 
Loaded plugins: fastestmirror
base                                                                                                                  | 3.6 kB  00:00:00     
epel                                                                                                                  | 4.7 kB  00:00:00     
extras                                                                                                                | 3.4 kB  00:00:00     
updates                                                                                                               | 3.4 kB  00:00:00     
(1/3): epel/x86_64/updateinfo                                                                                         | 908 kB  00:00:00     
(2/3): epel/x86_64/primary_db                                                                                         | 6.3 MB  00:00:00     
(3/3): updates/7/x86_64/primary_db                                                                                    | 6.9 MB  00:00:00     
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.56-2.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.56-2.el7 for package: 1:mariadb-5.5.56-2.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be updated
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================
 Package                             Arch                          Version                                 Repository                   Size
=============================================================================================================================================
Installing:
 mariadb                             x86_64                        1:5.5.56-2.el7                          base                        8.7 M
Updating for dependencies:
 mariadb-libs                        x86_64                        1:5.5.56-2.el7                          base                        757 k

Transaction Summary
=============================================================================================================================================
Install  1 Package
Upgrade             ( 1 Dependent package)

Total download size: 9.5 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): mariadb-libs-5.5.56-2.el7.x86_64.rpm                                                                           | 757 kB  00:00:00     
(2/2): mariadb-5.5.56-2.el7.x86_64.rpm                                                                                | 8.7 MB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                         35 MB/s | 9.5 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                        1/3 
  Installing : 1:mariadb-5.5.56-2.el7.x86_64                                                                                             2/3 
  Cleanup    : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                        3/3 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                        1/3 
  Verifying  : 1:mariadb-5.5.56-2.el7.x86_64                                                                                             2/3 
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                        3/3 

Installed:
  mariadb.x86_64 1:5.5.56-2.el7                                                                                                              

Dependency Updated:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                         

Complete!
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ sudo yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
No package mysql-server available.
Error: Nothing to do
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ sudo yum install mysql-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.56-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================
 Package                              Arch                          Version                                Repository                   Size
=============================================================================================================================================
Installing:
 mariadb-devel                        x86_64                        1:5.5.56-2.el7                         base                        752 k

Transaction Summary
=============================================================================================================================================
Install  1 Package

Total download size: 752 k
Installed size: 3.3 M
Is this ok [y/d/N]: y
Downloading packages:
mariadb-devel-5.5.56-2.el7.x86_64.rpm                                                                                 | 752 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-devel-5.5.56-2.el7.x86_64                                                                                       1/1 
  Verifying  : 1:mariadb-devel-5.5.56-2.el7.x86_64                                                                                       1/1 

Installed:
  mariadb-devel.x86_64 1:5.5.56-2.el7                                                                                                        

Complete!
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ service mysqld start
Redirecting to /bin/systemctl start  mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
Failed to start mysqld.service: Unit not found.
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ mysqladmin --version
mysqladmin  Ver 9.0 Distrib 5.5.56-MariaDB, for Linux on x86_64
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ sudo service mysqld start
Redirecting to /bin/systemctl start  mysqld.service
Failed to start mysqld.service: Unit not found.
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ sudo yum install -y mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.56-2.el7 will be installed
--> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.023-5.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 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:
 mariadb-server                              x86_64                     1:5.5.56-2.el7                        base                      11 M
Installing for dependencies:
 libaio                                      x86_64                     0.3.109-13.el7                        base                      24 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-DBD-MySQL                              x86_64                     4.023-5.el7                           base                     140 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  1 Package (+8 Dependent packages)

Total download size: 13 M
Installed size: 62 M
Downloading packages:
(1/9): libaio-0.3.109-13.el7.x86_64.rpm                                                                               |  24 kB  00:00:00     
(2/9): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                                                                 |  32 kB  00:00:00     
(3/9): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                                                                  |  57 kB  00:00:00     
(4/9): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm                                                                          | 140 kB  00:00:00     
(5/9): perl-DBI-1.627-4.el7.x86_64.rpm                                                                                | 802 kB  00:00:00     
(6/9): mariadb-server-5.5.56-2.el7.x86_64.rpm                                                                         |  11 MB  00:00:00     
(7/9): perl-IO-Compress-2.061-2.el7.noarch.rpm                                                                        | 260 kB  00:00:00     
(8/9): perl-Net-Daemon-0.48-5.el7.noarch.rpm                                                                          |  51 kB  00:00:00     
(9/9): perl-PlRPC-0.2020-14.el7.noarch.rpm                                                                            |  36 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                         32 MB/s |  13 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libaio-0.3.109-13.el7.x86_64                                                                                              1/9 
  Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                                                2/9 
  Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                                               3/9 
  Installing : perl-IO-Compress-2.061-2.el7.noarch                                                                                       4/9 
  Installing : perl-Net-Daemon-0.48-5.el7.noarch                                                                                         5/9 
  Installing : perl-PlRPC-0.2020-14.el7.noarch                                                                                           6/9 
  Installing : perl-DBI-1.627-4.el7.x86_64                                                                                               7/9 
  Installing : perl-DBD-MySQL-4.023-5.el7.x86_64                                                                                         8/9 
  Installing : 1:mariadb-server-5.5.56-2.el7.x86_64                                                                                      9/9 
  Verifying  : perl-DBI-1.627-4.el7.x86_64                                                                                               1/9 
  Verifying  : perl-Net-Daemon-0.48-5.el7.noarch                                                                                         2/9 
  Verifying  : perl-PlRPC-0.2020-14.el7.noarch                                                                                           3/9 
  Verifying  : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                                               4/9 
  Verifying  : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                                                5/9 
  Verifying  : 1:mariadb-server-5.5.56-2.el7.x86_64                                                                                      6/9 
  Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                              7/9 
  Verifying  : perl-DBD-MySQL-4.023-5.el7.x86_64                                                                                         8/9 
  Verifying  : perl-IO-Compress-2.061-2.el7.noarch                                                                                       9/9 

Installed:
  mariadb-server.x86_64 1:5.5.56-2.el7                                                                                                       

Dependency Installed:
  libaio.x86_64 0:0.3.109-13.el7           perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7      perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7     
  perl-DBD-MySQL.x86_64 0:4.023-5.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                

Complete!
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ systemctl start mariadb.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ sudo systemctl start mariadb.service
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ sudo  systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ mysql_sceure_installation
-bash: mysql_sceure_installation: command not found
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show dbs
    -> exit
    -> eCtrl-C -- exit!
Aborted
[admin@iz2ze0pyv80iyyiundbb5oz ~]$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> 

阅读更多

扫码向博主提问

xudailong_blog

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • python爬虫
  • 分布式爬虫
  • linux
  • 爬虫接单
  • 售卖爬虫源码
去开通我的Chat快问
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页