66 lines
1.5 KiB
Markdown
66 lines
1.5 KiB
Markdown
|
# MariaDB 安装配置与使用
|
||
|
|
||
|
MariaDB 是与 MySQL 兼容的开源实现,当 Linux 服务器上需要使用 MySQL 时可以用 MariaDB 替代。
|
||
|
|
||
|
## 安装
|
||
|
|
||
|
MariaDB 的安装命令如下:
|
||
|
|
||
|
```sh
|
||
|
## Arch Linux
|
||
|
pacman -S mariadb mariadb-clients mariadb-libs
|
||
|
## Ubuntu
|
||
|
apt-get install mariadb-server mariadb-client libmariadbclient-dev
|
||
|
```
|
||
|
|
||
|
## 初始配置
|
||
|
|
||
|
安装完 MariaDB 后需要进行初始配置,首先需要执行以下命令:
|
||
|
|
||
|
```sh
|
||
|
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
|
||
|
```
|
||
|
|
||
|
之后启动 MariaDB 的系统服务:
|
||
|
|
||
|
```sh
|
||
|
systemctl start mariadb
|
||
|
```
|
||
|
|
||
|
最后初始化数据库:
|
||
|
|
||
|
```sh
|
||
|
mysql_secure_installation
|
||
|
|
||
|
Switch to unix_socket authentication [Y/n] n
|
||
|
Change the root password? [Y/n] Y
|
||
|
Remove anonymous users? [Y/n] Y
|
||
|
Disallow root login remotely? [Y/n] n
|
||
|
Remove test database and access to it? [Y/n] Y
|
||
|
Reload privilege tables now? [Y/n] Y
|
||
|
... Success!
|
||
|
```
|
||
|
|
||
|
## 基本维护
|
||
|
|
||
|
```sh
|
||
|
# 进入 MariaDB 交互模式
|
||
|
mariadb -u root -p
|
||
|
# 显示所有数据库
|
||
|
show databases;
|
||
|
# 删除数据库
|
||
|
drop database <database name>;
|
||
|
# 选择操作的数据库
|
||
|
use mysql;
|
||
|
# 更改密码
|
||
|
update user set authentication_string=PASSWORD('passwd') where User='root';
|
||
|
# 如果没这一行可能也会报一个错误,因此需要运行这一行
|
||
|
update user set plugin="mysql_native_password";
|
||
|
# 强制写入
|
||
|
flush privileges;
|
||
|
# 退出
|
||
|
quit;
|
||
|
# 重启 MariaDB 服务使新的配置生效
|
||
|
systemctl restart mariadb
|
||
|
```
|