From b24a110b412478244689ad5e9f27d6b2b28882c7 Mon Sep 17 00:00:00 2001 From: "ithink.chan" Date: Tue, 16 Jul 2019 09:57:00 +0800 Subject: [PATCH] =?UTF-8?q?MariaDB=20=E5=AE=89=E8=A3=85=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=8E=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ithink.chan --- .../MariaDB/MariaDB_安装配置与使用.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Software/Application/MariaDB/MariaDB_安装配置与使用.md diff --git a/Software/Application/MariaDB/MariaDB_安装配置与使用.md b/Software/Application/MariaDB/MariaDB_安装配置与使用.md new file mode 100644 index 0000000..b03529c --- /dev/null +++ b/Software/Application/MariaDB/MariaDB_安装配置与使用.md @@ -0,0 +1,65 @@ +# 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 ; +# 选择操作的数据库 +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 +```