在 Centos 8 上安装默认的 mariadb

你只需要执行:
1 | dnf install mariadb-server |
上面的命令进行安装就可以了。
通过命令查看运行数据库的版本:
systemctl status mariadb
常用命令:
1 2 3 4 5 | systemctl start mariadb #启动服务 systemctl enable mariadb #设置开机启动 systemctl restart mariadb #重新启动 systemctl stop mariadb.service #停止MariaDB |
登录到数据库用
1 | mysql -uroot; |
登录到MariaDB,此时root账户的密码为空,直接回车即可,退出Mariadb,exit;即可。
进行MariaDB的相关简单配置
使用命令进行配置:
1 | [root@auto- test ~] # mysql_secure_installation |
1.首先是设置密码,会提示先输入密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 首先是设置密码,会提示先输入密码 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完成,接下来测试登录
1 | [root@auto-test ~]# mysql -uroot -proot; |
2.配置MariaDB的字符集
查看/etc/my.cnf文件内容,其中包含一句!includedir /etc/my.cnf.d 说明在该配置文件中引入/etc/my.cnf.d 目录下的配置文件。
使用使用vim /etc/my.cnf.d/mariadb-server.cnf命令编辑mariadb-server.cnf文件,在[mysqld]标签下添加
1 2 3 4 5 6 | [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 |
配置完成,重启mariadb
1 | systemctl restart mariadb |
之后进入MariaDB查看字符集
1 | mysql> show variables like "%character%" ;show variables like "%collation%" ; |
显示为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | +————————–+—————————-+ | 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) |
字符集配置完成。
4.添加用户,设置权限
创建用户命令
1 | mysql>create user username@localhost identified by 'password' ; |
直接创建用户并授权的命令
1 | mysql>grant all on *.* to username@localhost indentified by 'password' ; |
授予外网登陆权限
1 | mysql>grant all privileges on *.* to username@ '%' identified by 'password' ; |
授予权限并且可以授权
1 | mysql>grant all privileges on *.* to username@ 'hostname' identified by 'password' with grant option; |
查看用户
1 | MariaDB [mysql]> select host,user,password from user; |
允许指定地址远程
1 | GRANT ALL PRIVILEGES ON *.* TO 'root' @ '193.112.125.229' WITH GRANT OPTION; |
重载
1 | FLUSH PRIVILEGES; |
原文地址:https://www.cnblogs.com/yizhipanghu/p/15591930.html



本文作者:zhongming 文章标题: 在 Centos 8 上安装默认的 mariadb
本文地址:https://www.zhong-ming.com/index.php/2022/03/15/mariadbinstall/
版权声明:若无注明,本文皆为“zhongming”原创,转载请保留文章出处。
本文地址:https://www.zhong-ming.com/index.php/2022/03/15/mariadbinstall/
版权声明:若无注明,本文皆为“zhongming”原创,转载请保留文章出处。

近期评论