MariaDB 系统安装配置

简单记录一下在 CentOS 系统上安装 MariaDB 的过程。

安装命令

$: yum install mariadb mariadb-server
$: systemctl start mariadb      #启动服务
$: systemctl enable mariadb     #开机启动
$: mysql_secure_installation    #设置密码
$: mysql -uroot -p

迁移存储目录

当前数据存储目录:

mysql> selet @@datadir;
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+

停服,迁移目录:

$: systemctl stop mysql
$: mv /var/lib/mysql/ /data/mysql   #移动到存储磁盘所在路径
$: ln -s /data/mysql /var/lib/mysql #软链
$: systemctl start mysql 

基础 SQL

管理用户

# 创建用户
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; # 本地访问
mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'password';         # 远程访问

# 更新密码
mysql> UPDATE USER SET PASSWORD = 'new_password' WHERE USER = 'username';

管理数据库

# 创建数据库
mysql> CREATE DATABASE `db_name`;

# 用户授权
mysql> GRANT ALL PRIVILEGES ON `db_name`.* to 'username'@'localhost';
mysql> GRANT ALL PRIVILEGES ON `db_name`.* to 'username'@'%'; 
mysql> FLUSH PRIVILEGES;

# 删除数据库
mysql> DROP DATABASE `db_name`;

← Postfix 邮件系统搭建 None

评论