Centos7安装mariaDB

Installing MariaDB Server 10.4

To deploy MariaDB Community Server 10.4 on RHEL 7 or CentOS 7, first download and use the mariadb_repo_setup script to configure the MariaDB repositories for YUM:

$ sudo yum install wget
$ wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
$ chmod +x mariadb_repo_setup
$ sudo ./mariadb_repo_setup

To install MariaDB Community Server and dependencies:

$ sudo yum install MariaDB-server -y

Configuring and Securing MariaDB Server

Start the systemd service for MariaDB Server 5.5 or 10.4 using systemctl:

$ sudo systemctl start mariadb

设置开机启动
systemctl enable mariadb

Specific security practices should always follow any business-specific requirements and governance. Some basic steps should be taken to help harden the MariaDB Community Server 5.5 or 10.4 deployment:

$ sudo mariadb-secure-installation

1.输入当前密码,初次安装后是没有密码的,直接回车
2.询问是否使用 'unix_socket' 进行身份验证: n
3.为 root 设置密码:y
4.输入 root 的新密码: root
5.确认输入 root 的新密码: root
6.是否移除匿名用户,这个随意,建议删除: y
7.拒绝用户远程登录,这个建议开启:n
8.删除 test 库,可以保留:n
9.重新加载权限表:y
 
 
mariadb不支持utf8mb3 用下面sql批量替换下编码

select concat('ALTER TABLE ',TABLE_Name, ' MODIFY `',COLUMN_NAME, '` ' , COLUMN_TYPE, ' CHARACTER SET utf8mb4;') command
from information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'mytest'
and CHARACTER_SET_NAME = 'utf8mb3';

  
2.重启mariadb服务,读取my.cnf新配置
systemctl restart mariadb
 
 
 

MySQL创建用户与授权

 

一. 创建用户

命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';

说明:
username:你将创建的用户名
host:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%
password:该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器
例子:
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';


二. 授权:

命令:GRANT privileges ON databasename.tablename TO 'username'@'host'

说明:
privileges:用户的操作权限,如SELECT,INSERT,UPDATE等,如果要授予所的权限则使用ALL
databasename:数据库名
tablename:表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*表示,如*.*
例子:
GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
GRANT ALL ON maindataplus.* TO 'pig'@'%';
注意:
用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

 

CENTOS7设置时区

不考虑各个发行版的差异化, 从更底层出发的话, 修改时间时区比想象中要简单:

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

posted @ 2022-05-30 02:26  小谭行天下  阅读(297)  评论(0编辑  收藏  举报