当前位置: 首页 > 数据库 > mysql >

CentOS7.4使用yum安装MariaDB

一、创建MariaDB.repo文件
 
[root@localhost ~]# vi /etc/yum.repos.d/MariaDB.repo

# MariaDB 10.4 RedHat repository list - created 2020-02-15 03:58 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

//如果当前源版本失效,可以从 https://downloads.mariadb.org/mariadb/repositories/ 复制新的可用yum源
 
二、运行安装命令安装MariaDB
 
[root@localhost ~]# yum -y install mariadb-server mariadb-client
 
 
systemctl start mariadb #启动服务
systemctl enable mariadb #设置开机启动
systemctl restart mariadb #重新启动
systemctl stop mariadb.service #停止MariaDB
 
登录到数据库,用mysql -uroot命令登录到MariaDB,此时root账户的密码为空。
 
  [root@localhost ~]#  mysql
 
进行MariaDB的相关简单配置,使用mysql_secure_installation命令进行配置。
 
 [root@localhost ~]#  mysql_secure_installation
 
首先是设置密码,会提示先输入密码 Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <–是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车 初始化MariaDB完成,接下来测试登录
mysql -uroot -p password
 
完成。
 
配置MariaDB的字符集
 
查看/etc/my.cnf文件内容,其中包含一句!includedir /etc/my.cnf.d 说明在该配置文件中引入/etc/my.cnf.d 目录下的配置文件。
 
1)使用vi server.cnf命令编辑server.cnf文件,在[mysqld]标签下添加
 
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8' 
character-set-server=utf8
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake
 
 
如果/etc/my.cnf.d 目录下无server.cnf文件,则直接在/etc/my.cnf文件的[mysqld]标签下添加以上内容。
 
2)文件/etc/my.cnf.d/client.cnf
 
   [root@localhost ~]#  vi /etc/my.cnf.d/client.cnf
 
在[client]中添加
 
[client]
default-character-set=utf8
 
3)文件/etc/my.cnf.d/mysql-clients.cnf
 
[root@localhost ~]# vi /etc/my.cnf.d/mysql-clients.cnf
//在[mysql]中添加
[mysql]
default-character-set=utf8
 
全部配置完成,重启mariadb
 
[root@localhost ~]# systemctl restart mariadb
 
之后进入MariaDB查看字符集
 
mysql> show variables like "%character%";show variables like "%collation%";
 
显示为
±-------------------------±---------------------------+
| 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)
 
±---------------------±----------------+
| Variable_name | Value |
±---------------------±----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
±---------------------±----------------+
3 rows in set (0.00 sec)
 
字符集配置完成。
 
添加用户,设置权限
 
创建用户命令
 
mysql>create user username@localhost identified by 'password';
 
直接创建用户并授权的命令
 
mysql>grant all on *.* to username@localhost indentified by 'password';
 
授予外网登陆权限
 
mysql>grant all privileges on *.* to username@'%' identified by 'password';
 
授予权限并且可以授权
 
  mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;
 
进入到数据库
 
MariaDB [mysql]> select host,user,password from user;
 
±----------------------±------±-----------------------+
| host | user | password |
±----------------------±------±-----------------------+
| localhost | root | *E87F9354F7E889A65E… |
| localhost.localdomain | root | *E87F9354F7E889A65E… |
| 127.0.0.1 | root | *E87F9354F7E889A65E… |
| ::1 | root | *E87F9354F7E889A65E… |
| localhost | | |
| localhost.localdomain | | |
±----------------------±------±-----------------------+
7 rows in set (0.00 sec)
查询各Schema和Table占用的空间:
 
MariaDB [information_schema]> use information_schema;
MariaDB [information_schema]> select table_schema,round(sum(DATA_LENGTH/1024/1024),2) as datasize  from tables group by table_schema;
 
±-------------------±---------+
| table_schema | datasize |
±-------------------±---------+
| common | 0.05 |
| information_schema | 0.09 |
| mysql | 9.11 |
| nemo | 103.23 |
| river | 3.78 |
±-------------------±---------+
5 rows in set (2.026 sec)
 
MariaDB [information_schema]> select table_name,concat(round(sum(data_length/1024/1024),2),'MB') as datasize from tables where table_schema='nemo' group by table_name;
 
±--------------------------------±---------+
| table_name | datasize |
±--------------------------------±---------+
| actions             | 0.05MB |
| addresses            | 0.02MB |
| addressfieldattributes    | 0.02MB |
| addressprops          | 0.02MB |
| composedtypes        | 1.52MB |
| composedtypeslp        | 1.52MB |
| comptypegrp2comptype    | 0.05MB |
| config             | 0.02MB |
| itemcockpittemplrels    | 0.02MB |
| itemsynctimestamps    | 2.52MB |
| keyfeature          | 0.02MB |
| keyfeaturelp        | 0.02MB |
| keyvaluemap           | 2.52MB |
| keywords            | 0.02MB |
| keywordsuggestionrule    | 0.02MB |
±--------------------------------±---------+
15 rows in set (0.544 sec)


防火墙放开服务:

 

端口方式

firewall-cmd --zone=public --add-port=3306/tcp --permanent

 

或者服务方式(只需其一)

firewall-cmd --zone=public --permanent --add-service=mysql

 

 

firewall-cmd --reload

 
 
完成mariadb的简单配置
————————————————
版权声明:本文为CSDN博主「华夏(0.0)战火�」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44194491/article/details/94596704
------分隔线----------------------------
  • 收藏
  • 挑错
  • 推荐
  • 打印