0
点赞
收藏
分享

微信扫一扫

yum 安装mariadb

编程练习生J 2022-08-02 阅读 209


1、添加源 vi /etc/yum.repos.d/MariaDB.repo

[mariadb]

name = MariaDB

baseurl = https://mirrors.aliyun.com/mariadb/yum/10.5/centos7-amd64

gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck=1


yum install MariaDB-server MariaDB-client

systemctl start mariadb

systemctl enable mariadb


2、接下来进行MariaDB的相关简单配置:

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完成,接下来测试登录


3、mysql -uroot -ppassword


4、配置MariaDB的字符集

修改文件/etc/my.cnf

vi /etc/my.cnf

在[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

vi /etc/my.cnf.d/client.cnf

在[client]中添加

default-character-set=utf8


vi /etc/my.cnf.d/mysql-clients.cnf

在[mysql]中添加

default-character-set=utf8

全部配置完成,重启mariadb


systemctl restart mariadb

之后进入MariaDB查看字符集


mysql> show variables like "%character%";

show variables like "%collation%";


5、添加用户,设置权限

创建用户命令


mysql>create user root@localhost identified by 'password';

直接创建用户并授权的命令


mysql>grant all on \*.\* to root@localhost indentified by 'password';

授予外网登陆权限


mysql>grant all privileges on \*.\* to root@'%' identified by 'password';

授予权限并且可以授权


mysql>grant all privileges on \*.\* to root@'hostname' identified by 'password' with grant option;

简单的用户和权限配置基本就这样了。


6、mysql忘记密码

在数据库配置文件/etc/my.cnf中的[mysqld]下面添加skip-grant-tables,保存退出,重启mysql服务;


6.1、进入mysql数据库,给root用户设置新密码,蓝色部分自己输入

mysql> use mysql

mysql> update user set password=password("123456") where user="root";

Query OK, 1 rows affected (0.04 sec)Rows matched: 1 Changed: 1 Warnings: 0


6.2、刷新数据库,然后退出

mysql> flush privileges;


windows安装:https://www.cnblogs.com/javaxubo/articles/15307383.html
官网:https://mariadb.org/download/?t=repo-config
镜像:https://www.huaweicloud.com/special/mariadb-jingxiang.html


举报

相关推荐

0 条评论