Centos 安装配置MariaDB(MySQL)

以下流程亲测已过


[root@dbServer ~]# yum install -y mariadb mariadb-server

已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb.x86_64.1.5.5.52-1.el7 将被 安装
--> 正在处理依赖关系 mariadb-libs(x86-64) = 1:5.5.52-1.el7,它被软件包 1:mariadb-5.5.52-1.el7.x86_64 需要
---> 软件包 mariadb-server.x86_64.1.5.5.52-1.el7 将被 安装
--> 正在处理依赖关系 perl-DBD-MySQL,它被软件包 1:mariadb-server-5.5.52-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 安装
---> 软件包 perl-DBD-MySQL.x86_64.0.4.023-5.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决
====================================================================================
 Package                                       架构                                  版本                                          源                                   大小
=============================================================================================================================
正在安装:
 mariadb                                       x86_64                                1:5.5.52-1.el7                                base                                8.7 M
 mariadb-server                                x86_64                                1:5.5.52-1.el7                                base                                 11 M
为依赖而安装:
 mariadb-libs                                  x86_64                                1:5.5.52-1.el7                                base                                761 k
 perl-DBD-MySQL                                x86_64                                4.023-5.el7                                   base                                140 k

事务概要
==============================================================================================================================
安装  2 软件包 (+2 依赖软件包)

总下载量:20 M
安装大小:109 M
Downloading packages:
(1/4): mariadb-libs-5.5.52-1.el7.x86_64.rpm                                                                                                           | 761 kB  00:00:00     
(2/4): mariadb-5.5.52-1.el7.x86_64.rpm                                                                                                                | 8.7 MB  00:00:08     
(3/4): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm                                                                                                          | 140 kB  00:00:00     
(4/4): mariadb-server-5.5.52-1.el7.x86_64.rpm                                                                                                         |  11 MB  00:00:10     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                         1.8 MB/s |  20 MB  00:00:11     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                       1/4
  正在安装    : perl-DBD-MySQL-4.023-5.el7.x86_64                                                                                                                        2/4
  正在安装    : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                            3/4
  正在安装    : 1:mariadb-server-5.5.52-1.el7.x86_64                                                                                                                     4/4
  验证中      : 1:mariadb-server-5.5.52-1.el7.x86_64                                                                                                                     1/4
  验证中      : perl-DBD-MySQL-4.023-5.el7.x86_64                                                                                                                        2/4
  验证中      : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                            3/4
  验证中      : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                       4/4
已安装:
  mariadb.x86_64 1:5.5.52-1.el7                                                     mariadb-server.x86_64 1:5.5.52-1.el7                                                   
作为依赖被安装:
  mariadb-libs.x86_64 1:5.5.52-1.el7                                                   perl-DBD-MySQL.x86_64 0:4.023-5.el7                                                 
完毕!
[root@dbServer ~]# 


[root@dbServer ~]# systemctl start mariadb
[root@dbServer ~]# systemctl enable mariadb

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@dbServer ~]#

[root@dbServer ~]# mysql_secure_installation
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] n
 ... 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] n
 ... skipping.
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!

[root@dbServer ~]# MySQL -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> 
MariaDB [(none)]> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

字符集备注:

character_set_client:客户端请求数据的字符集。
character_set_connection:从客户端接收到数据,然后传输的字符集。
character_set_database:默认数据库的字符集,无论默认数据库如何改变,都是这个字符集;如果没有默认数据库,使character_set_server指定的字符集,此参数无需设置。
character_set_filesystem:把character_set_client转换character_set_filesystem,默认binary即可
character_set_results:结果集的字符集。
character_set_server:数据库服务器的默认字符集。
character_set_system:这个值总是utf8,不需要设置,存储系统元数据的字符集

MariaDB [(none)]> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> set character_set_server=utf8;
Query OK, 0 rows affected (0.00 sec)


MariaDB [(none)]> create database jobHunter;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> use jobHunter;
Database changed
MariaDB [jobHunter]> source /root/createtable.sql
Query OK, 0 rows affected (0.01 sec)



可能存在问题:

修改好了字符集,但是重新进入数据库时,编码丢失。

如下,也就是可能SET character_set_database = utf8;命令失效

MariaDB [(none)]> SET character_set_database = utf8;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> commit;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 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)

MariaDB [(none)]> exit
Bye
[root@hadron ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.52-MariaDB MariaDB Server

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

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

MariaDB [(none)]> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)


如果出现上面问题,那只好去修改配置文件了,如下:

[root@hadron /]# vi /etc/my.cnf

[mysqld]
character-set-server=utf8
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8


[root@hadron /]# systemctl restart mariadb
[root@hadron /]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

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

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

MariaDB [(none)]> show variables like "%collation%";
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>  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)

MariaDB [(none)]> 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个错误提示表明你在安装软件时遇到了库依赖冲突的问题,可能是因为你同时安装了不同版本的软件包或者库。这种情况下,你需要检查一下你的系统中已经安装软件包和库的版本,然后尝试解决冲突。 具体来说,你需要先卸载掉 mariadb-libsmysql-community-libs-compat 这两个软件包,再重新安装 mariadb-libs,这样就可以解决冲突问题了。 你可以按照以下步骤操作: 1. 卸载 mariadb-libsmysql-community-libs-compat: ``` sudo yum remove mariadb-libs mysql-community-libs-compat ``` 2. 安装 mariadb-libs: ``` sudo yum install mariadb-libs ``` 如果你还遇到其他依赖问题,可以根据提示信息继续解决。 ### 回答2: 这个错误显示在更新或安装软件包时出现了依赖检测失败的情况。具体来说,错误提示是"mariadb-libs"被"mysql-community-libs-5.7.42-1.el7.x86_64"取代,"mariadb-libs"也被"mysql-community-libs-compat-5.7.42-1.el7.x86_64"取代。 造成这个错误的原因可能是系统中已经安装了较新版本的"mysql-community-libs"和"mysql-community-libs-compat"软件包,而安装软件包需要较旧版本的"mariadb-libs"。这可能是因为软件包版本兼容性的问题。 要解决这个错误,有几个可能的方法可以尝试: 1. 删除已经安装的"mysql-community-libs"和"mysql-community-libs-compat"软件包,然后重新安装需要的"mariadb-libs"软件包。 2. 更新安装软件包到与要求的版本兼容的最新版本。这可能需要从官方软件源或其他可靠的软件源重新安装软件包,确保选择正确的版本。 3. 在安装或更新软件包时,使用命令中的参数来覆盖依赖检测,强制安装或更新软件包,尽管存在兼容性问题。这种方法可能会导致其他问题,因此需要谨慎使用。 在处理依赖检测失败的问题时,重要的是要确保所安装软件包版本兼容,并且从可靠的来源获取软件包。 ### 回答3: 依赖检测失败是指在安装某个软件包时,系统无法满足该软件包依赖关系,导致安装失败。在这个错误中,mariadb-libsmysql-community-libs-5.7.42-1.el7.x86_64 替代了,而 mariadb-libs 还被 mysql-community-libs-compat-5.7.42-1.el7.x86_64 替代了。 这个错误可能是由于系统中已经安装了类似的软件包,而且版本不兼容所造成的。mariadb-libsmysql-community-libs 是两个不同的软件包,可能在功能上有一些相似之处,但版本不同,因此无法替代对方。同样,mariadb-libsmysql-community-libs-compat 也是不同的软件包,具有不同的版本和功能。 要解决这个错误,可以尝试以下几种方法: 1. 卸载已安装的不兼容软件包:使用包管理器(如yum)将已安装的不兼容软件包进行卸载,然后重新安装所需的软件包。 2. 更新软件源:更新系统的软件源,使用最新的软件源可以确保安装软件包能够满足依赖关系。 3. 更改安装源:将软件包安装源更改为兼容的版本,以便能够满足依赖关系。 4. 手动安装依赖软件包:如果以上方法都无法解决问题,可以尝试手动下载并安装依赖的软件包,以满足安装需求。 总之,依赖检测失败是由于软件包依赖关系无法满足而导致的安装失败,需要通过卸载或更换软件包来解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值