Centos7 安装mairadb
1.yum -y install mysql
默认安装的是mariadb,之后用命令:mysql,总是出现:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
2.之后再运行:
[root@localhost ~]# yum -y install mariadb* 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.opencas.cn * extras: mirrors.yun-idc.com * updates: mirrors.opencas.cn 软件包 1:mariadb-5.5.44-1.el7_1.x86_64 已安装并且是最新版本 软件包 1:mariadb-libs-5.5.44-1.el7_1.x86_64 已安装并且是最新版本 正在解决依赖关系 --> 正在检查事务 ---> 软件包 mariadb-bench.x86_64.1.5.5.44-1.el7_1 将被 安装 --> 正在处理依赖关系 perl(GD),它被软件包 1:mariadb-bench-5.5.44-1.el7_1.x86_64 需要 --> 正在处理依赖关系 perl(Data::Dumper),它被软件包 1:mariadb-bench-5.5.44-1.el7_1.x86_64 需要 --> 正在处理依赖关系 perl(DBI),它被软件包 1:mariadb-bench-5.5.44-1.el7_1.x86_64 需要 ---> 软件包 mariadb-devel.x86_64.1.5.5.44-1.el7_1 将被 安装 --> 正在处理依赖关系 openssl-devel(x86-64),它被软件包 1:mariadb-devel-5.5.44-1.el7_1.x86_64 需要 ---> 软件包 mariadb-embedded.x86_64.1.5.5.44-1.el7_1 将被 安装 ---> 软件包 mariadb-embedded-devel.x86_64.1.5.5.44-1.el7_1 将被 安装 ---> 软件包 mariadb-server.x86_64.1.5.5.44-1.el7_1 将被 安装 --> 正在处理依赖关系 perl-DBD-MySQL,它被软件包 1:mariadb-server-5.5.44-1.el7_1.x86_64 需要 ---> 软件包 mariadb-test.x86_64.1.5.5.44-1.el7_1 将被 安装 --> 正在处理依赖关系 perl(Test::More),它被软件包 1:mariadb-test-5.5.44-1.el7_1.x86_64 需要 --> 正在处理依赖关系 perl(Env),它被软件包 1:mariadb-test-5.5.44-1.el7_1.x86_64 需要 --> 正在检查事务 ---> 软件包 openssl-devel.x86_64.1.1.0.1e-42.el7.9 将被 安装 --> 正在处理依赖关系 zlib-devel(x86-64),它被软件包 1:openssl-devel-1.0.1e-42.el7.9.x86_64 需要 --> 正在处理依赖关系 krb5-devel(x86-64),它被软件包 1:openssl-devel-1.0.1e-42.el7.9.x86_64 需要 ---> 软件包 perl-DBD-MySQL.x86_64.0.4.023-5.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 将被 安装 ---> 软件包 perl-Env.noarch.0.1.04-2.el7 将被 安装 ---> 软件包 perl-GD.x86_64.0.2.49-3.el7 将被 安装 --> 正在处理依赖关系 gd >= 2.0.28,它被软件包 perl-GD-2.49-3.el7.x86_64 需要 --> 正在处理依赖关系 libgd.so.2()(64bit),它被软件包 perl-GD-2.49-3.el7.x86_64 需要 --> 正在处理依赖关系 libXpm.so.4()(64bit),它被软件包 perl-GD-2.49-3.el7.x86_64 需要 ---> 软件包 perl-Test-Simple.noarch.0.0.98-243.el7 将被 安装 --> 正在处理依赖关系 perl(Test::Harness) >= 2.03,它被软件包 perl-Test-Simple-0.98-243.el7.noarch 需要 --> 正在检查事务 ---> 软件包 gd.x86_64.0.2.0.35-26.el7 将被 安装 ---> 软件包 krb5-devel.x86_64.0.1.12.2-15.el7_1 将被 安装 --> 正在处理依赖关系 libverto-devel,它被软件包 krb5-devel-1.12.2-15.el7_1.x86_64 需要 --> 正在处理依赖关系 libselinux-devel,它被软件包 krb5-devel-1.12.2-15.el7_1.x86_64 需要 --> 正在处理依赖关系 libcom_err-devel,它被软件包 krb5-devel-1.12.2-15.el7_1.x86_64 需要 --> 正在处理依赖关系 keyutils-libs-devel,它被软件包 krb5-devel-1.12.2-15.el7_1.x86_64 需要 ---> 软件包 libXpm.x86_64.0.3.5.10-5.1.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-Test-Harness.noarch.0.3.28-2.el7 将被 安装 ---> 软件包 zlib-devel.x86_64.0.1.2.7-13.el7 将被 安装 --> 正在检查事务 ---> 软件包 keyutils-libs-devel.x86_64.0.1.5.8-3.el7 将被 安装 ---> 软件包 libcom_err-devel.x86_64.0.1.42.9-7.el7 将被 安装 ---> 软件包 libselinux-devel.x86_64.0.2.2.2-6.el7 将被 安装 --> 正在处理依赖关系 libsepol-devel >= 2.1.9-1,它被软件包 libselinux-devel-2.2.2-6.el7.x86_64 需要 --> 正在处理依赖关系 pkgconfig(libsepol),它被软件包 libselinux-devel-2.2.2-6.el7.x86_64 需要 --> 正在处理依赖关系 pkgconfig(libpcre),它被软件包 libselinux-devel-2.2.2-6.el7.x86_64 需要 ---> 软件包 libverto-devel.x86_64.0.0.2.5-4.el7 将被 安装 ---> 软件包 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 将被 安装 --> 正在检查事务 ---> 软件包 libsepol-devel.x86_64.0.2.1.9-3.el7 将被 安装 ---> 软件包 pcre-devel.x86_64.0.8.32-14.el7 将被 安装 ---> 软件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 将被 安装 ---> 软件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ==================================================================================================== Package 架构 版本 源 大小 ==================================================================================================== 正在安装: mariadb-bench x86_64 1:5.5.44-1.el7_1 updates 385 k mariadb-devel x86_64 1:5.5.44-1.el7_1 updates 747 k mariadb-embedded x86_64 1:5.5.44-1.el7_1 updates 3.6 M mariadb-embedded-devel x86_64 1:5.5.44-1.el7_1 updates 7.4 M mariadb-server x86_64 1:5.5.44-1.el7_1 updates 11 M mariadb-test x86_64 1:5.5.44-1.el7_1 updates 8.0 M 为依赖而安装: gd x86_64 2.0.35-26.el7 base 146 k keyutils-libs-devel x86_64 1.5.8-3.el7 base 37 k krb5-devel x86_64 1.12.2-15.el7_1 updates 641 k libXpm x86_64 3.5.10-5.1.el7 base 52 k libcom_err-devel x86_64 1.42.9-7.el7 base 30 k libselinux-devel x86_64 2.2.2-6.el7 base 174 k libsepol-devel x86_64 2.1.9-3.el7 base 71 k libverto-devel x86_64 0.2.5-4.el7 base 12 k openssl-devel x86_64 1:1.0.1e-42.el7.9 updates 1.2 M pcre-devel x86_64 8.32-14.el7 base 477 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-Data-Dumper x86_64 2.145-3.el7 base 47 k perl-Env noarch 1.04-2.el7 base 16 k perl-GD x86_64 2.49-3.el7 base 173 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 perl-Test-Harness noarch 3.28-2.el7 base 302 k perl-Test-Simple noarch 0.98-243.el7 base 170 k zlib-devel x86_64 1.2.7-13.el7 base 49 k 事务概要 ==================================================================================================== 安装 6 软件包 (+23 依赖软件包) 总下载量:36 M 安装大小:237 M Downloading packages: (1/29): keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm | 37 kB 00:00:00 (2/29): gd-2.0.35-26.el7.x86_64.rpm | 146 kB 00:00:00 (3/29): libcom_err-devel-1.42.9-7.el7.x86_64.rpm | 30 kB 00:00:00 (4/29): libXpm-3.5.10-5.1.el7.x86_64.rpm | 52 kB 00:00:00 (5/29): libverto-devel-0.2.5-4.el7.x86_64.rpm | 12 kB 00:00:00 (6/29): krb5-devel-1.12.2-15.el7_1.x86_64.rpm | 641 kB 00:00:00 (7/29): libselinux-devel-2.2.2-6.el7.x86_64.rpm | 174 kB 00:00:00 (8/29): libsepol-devel-2.1.9-3.el7.x86_64.rpm | 71 kB 00:00:00 (9/29): mariadb-bench-5.5.44-1.el7_1.x86_64.rpm | 385 kB 00:00:00 (10/29): mariadb-devel-5.5.44-1.el7_1.x86_64.rpm | 747 kB 00:00:00 (11/29): mariadb-embedded-5.5.44-1.el7_1.x86_64.rpm | 3.6 MB 00:00:01 (12/29): openssl-devel-1.0.1e-42.el7.9.x86_64.rpm | 1.2 MB 00:00:01 (13/29): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00 (14/29): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00 (15/29): mariadb-server-5.5.44-1.el7_1.x86_64.rpm | 11 MB 00:00:02 (16/29): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm | 140 kB 00:00:00 (17/29): perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:00:00 (18/29): perl-Env-1.04-2.el7.noarch.rpm | 16 kB 00:00:00 (19/29): perl-GD-2.49-3.el7.x86_64.rpm | 173 kB 00:00:00 (20/29): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00 (21/29): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00 (22/29): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00 (23/29): pcre-devel-8.32-14.el7.x86_64.rpm | 477 kB 00:00:01 (24/29): perl-Test-Harness-3.28-2.el7.noarch.rpm | 302 kB 00:00:00 (25/29): perl-Test-Simple-0.98-243.el7.noarch.rpm | 170 kB 00:00:00 (26/29): zlib-devel-1.2.7-13.el7.x86_64.rpm | 49 kB 00:00:00 (27/29): mariadb-embedded-devel-5.5.44-1.el7_1.x86_64.rpm | 7.4 MB 00:00:05 (28/29): mariadb-test-5.5.44-1.el7_1.x86_64.rpm | 8.0 MB 00:00:11 (29/29): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:19 ---------------------------------------------------------------------------------------------------- 总计 1.6 MB/s | 36 MB 00:00:21 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : perl-Data-Dumper-2.145-3.el7.x86_64 1/29 正在安装 : libXpm-3.5.10-5.1.el7.x86_64 2/29 正在安装 : gd-2.0.35-26.el7.x86_64 3/29 正在安装 : perl-GD-2.49-3.el7.x86_64 4/29 正在安装 : libcom_err-devel-1.42.9-7.el7.x86_64 5/29 正在安装 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 6/29 正在安装 : perl-Net-Daemon-0.48-5.el7.noarch 7/29 正在安装 : zlib-devel-1.2.7-13.el7.x86_64 8/29 正在安装 : 1:mariadb-embedded-5.5.44-1.el7_1.x86_64 9/29 正在安装 : perl-Test-Harness-3.28-2.el7.noarch 10/29 正在安装 : perl-Test-Simple-0.98-243.el7.noarch 11/29 正在安装 : libverto-devel-0.2.5-4.el7.x86_64 12/29 正在安装 : perl-Env-1.04-2.el7.noarch 13/29 正在安装 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 14/29 正在安装 : perl-IO-Compress-2.061-2.el7.noarch 15/29 正在安装 : perl-PlRPC-0.2020-14.el7.noarch 16/29 正在安装 : perl-DBI-1.627-4.el7.x86_64 17/29 正在安装 : perl-DBD-MySQL-4.023-5.el7.x86_64 18/29 正在安装 : 1:mariadb-server-5.5.44-1.el7_1.x86_64 19/29 正在安装 : pcre-devel-8.32-14.el7.x86_64 20/29 正在安装 : libsepol-devel-2.1.9-3.el7.x86_64 21/29 正在安装 : libselinux-devel-2.2.2-6.el7.x86_64 22/29 正在安装 : keyutils-libs-devel-1.5.8-3.el7.x86_64 23/29 正在安装 : krb5-devel-1.12.2-15.el7_1.x86_64 24/29 正在安装 : 1:openssl-devel-1.0.1e-42.el7.9.x86_64 25/29 正在安装 : 1:mariadb-devel-5.5.44-1.el7_1.x86_64 26/29 正在安装 : 1:mariadb-embedded-devel-5.5.44-1.el7_1.x86_64 27/29 正在安装 : 1:mariadb-test-5.5.44-1.el7_1.x86_64 28/29 正在安装 : 1:mariadb-bench-5.5.44-1.el7_1.x86_64 29/29 验证中 : keyutils-libs-devel-1.5.8-3.el7.x86_64 1/29 验证中 : libsepol-devel-2.1.9-3.el7.x86_64 2/29 验证中 : 1:mariadb-bench-5.5.44-1.el7_1.x86_64 3/29 验证中 : pcre-devel-8.32-14.el7.x86_64 4/29 验证中 : perl-IO-Compress-2.061-2.el7.noarch 5/29 验证中 : libXpm-3.5.10-5.1.el7.x86_64 6/29 验证中 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 7/29 验证中 : perl-Env-1.04-2.el7.noarch 8/29 验证中 : perl-Test-Simple-0.98-243.el7.noarch 9/29 验证中 : perl-GD-2.49-3.el7.x86_64 10/29 验证中 : libverto-devel-0.2.5-4.el7.x86_64 11/29 验证中 : 1:mariadb-embedded-devel-5.5.44-1.el7_1.x86_64 12/29 验证中 : perl-Test-Harness-3.28-2.el7.noarch 13/29 验证中 : 1:openssl-devel-1.0.1e-42.el7.9.x86_64 14/29 验证中 : perl-DBD-MySQL-4.023-5.el7.x86_64 15/29 验证中 : 1:mariadb-embedded-5.5.44-1.el7_1.x86_64 16/29 验证中 : 1:mariadb-test-5.5.44-1.el7_1.x86_64 17/29 验证中 : libselinux-devel-2.2.2-6.el7.x86_64 18/29 验证中 : 1:mariadb-server-5.5.44-1.el7_1.x86_64 19/29 验证中 : perl-Data-Dumper-2.145-3.el7.x86_64 20/29 验证中 : gd-2.0.35-26.el7.x86_64 21/29 验证中 : zlib-devel-1.2.7-13.el7.x86_64 22/29 验证中 : perl-Net-Daemon-0.48-5.el7.noarch 23/29 验证中 : perl-PlRPC-0.2020-14.el7.noarch 24/29 验证中 : perl-DBI-1.627-4.el7.x86_64 25/29 验证中 : 1:mariadb-devel-5.5.44-1.el7_1.x86_64 26/29 验证中 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 27/29 验证中 : krb5-devel-1.12.2-15.el7_1.x86_64 28/29 验证中 : libcom_err-devel-1.42.9-7.el7.x86_64 29/29 已安装: mariadb-bench.x86_64 1:5.5.44-1.el7_1 mariadb-devel.x86_64 1:5.5.44-1.el7_1 mariadb-embedded.x86_64 1:5.5.44-1.el7_1 mariadb-embedded-devel.x86_64 1:5.5.44-1.el7_1 mariadb-server.x86_64 1:5.5.44-1.el7_1 mariadb-test.x86_64 1:5.5.44-1.el7_1 作为依赖被安装: gd.x86_64 0:2.0.35-26.el7 keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.12.2-15.el7_1 libXpm.x86_64 0:3.5.10-5.1.el7 libcom_err-devel.x86_64 0:1.42.9-7.el7 libselinux-devel.x86_64 0:2.2.2-6.el7 libsepol-devel.x86_64 0:2.1.9-3.el7 libverto-devel.x86_64 0:0.2.5-4.el7 openssl-devel.x86_64 1:1.0.1e-42.el7.9 pcre-devel.x86_64 0:8.32-14.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-Data-Dumper.x86_64 0:2.145-3.el7 perl-Env.noarch 0:1.04-2.el7 perl-GD.x86_64 0:2.49-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 perl-Test-Harness.noarch 0:3.28-2.el7 perl-Test-Simple.noarch 0:0.98-243.el7 zlib-devel.x86_64 0:1.2.7-13.el7 完毕!
3.
[root@localhost ~]# systemctl start mariadb.service [root@localhost ~]# systemctl enable mariadb.service ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service' [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.44-MariaDB MariaDB Server
4.设置root密码
[root@localhost ~]# mysql_secure_installation /usr/bin/mysql_secure_installation:行379: find_mysql_client: 未找到命令 NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, 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 MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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] y ... Success! By default, MariaDB 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 - Dropping test database... ... Success! - 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! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!