Centos8 安装mariaDB并配置
在 Centos 8 上,默认安装的 mariadb 服务器版本为:MariaDB Community Server 10.3
你只需要执行:
dnf install mariadb-server
上面的命令进行安装就可以了。
通过命令查看运行数据库的版本:
systemctl status mariadb
常用命令:
systemctl start mariadb #启动服务 systemctl enable mariadb #设置开机启动 systemctl restart mariadb #重新启动 systemctl stop mariadb.service #停止MariaDB
登录到数据库用
mysql -uroot;
登录到MariaDB,此时root账户的密码为空,直接回车即可,退出Mariadb,exit;即可。
进行MariaDB的相关简单配置
使用命令进行配置:
[root@auto-test ~]# mysql_secure_installation
1.首先是设置密码,会提示先输入密码
首先是设置密码,会提示先输入密码 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完成,接下来测试登录
[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]标签下添加
[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
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)
字符集配置完成。
4.添加用户,设置权限
创建用户命令
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;
允许指定地址远程
GRANT ALL PRIVILEGES ON *.* TO 'root'@'193.112.125.229'WITH GRANT OPTION;
重载
FLUSH PRIVILEGES;