修正 MariaDB 操作中的一些问题.

Signed-off-by: chen.yang <chen.yang@yuzhen-iot.com>
This commit is contained in:
chen.yang 2021-08-06 17:07:16 +08:00
parent ba5ad79394
commit 7bf0a7e958
3 changed files with 24 additions and 19 deletions

View File

@ -16,7 +16,7 @@ published: true
```bash
# Ubuntu
apt install docker.io
# Arch Linux/Manjaro
# Manjaro
pacman -S docker
```

View File

@ -7,10 +7,10 @@ MariaDB 是与 MySQL 兼容的开源实现,当 Linux 服务器上需要使用
MariaDB 的安装命令如下:
```bash
## Arch Linux
pacman -S mariadb mariadb-clients mariadb-libs
## Ubuntu
apt install mariadb-server mariadb-client libmariadb-dev libmariadbclient-dev
# Manjaro
sudo pacman -S mariadb mariadb-clients mariadb-libs
# Ubuntu
sudo apt install mariadb-server mariadb-client libmariadb-dev libmariadbclient-dev
```
## 2.初始配置
@ -18,13 +18,16 @@ apt install mariadb-server mariadb-client libmariadb-dev libmariadbclient-dev
安装完 MariaDB 后需要进行初始配置,首先需要执行以下命令:
```bash
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
# Manjaro
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
# Ubuntu ?
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
```
之后启动 MariaDB 的系统服务:
```bash
systemctl start mariadb
sudo systemctl start mariadb
```
最后初始化数据库:
@ -53,9 +56,9 @@ mariadb -u root -p
mariadb -h localhost -u root -p
# 更改密码(解决普通用户登陆报错Access denied for user 'root'@'localhost'),请将'passwd'替换为实际的密码
update user set authentication_string=PASSWORD('passwd') where user='root';
UPDATE mysql.user set authentication_string=PASSWORD('passwd') where user='root';
# 如果没这一行可能也会报一个错误,因此需要运行这一行
update user set plugin="mysql_native_password";
UPDATE mysql.user set plugin="mysql_native_password";
# 强制写入,操作完退出前先进行以下该操作
FLUSH privileges;
@ -76,13 +79,13 @@ SHOW global variables like 'port';
```bash
# 显示所有数据库
SHOW databases;
SHOW DATABASES;
# 删除数据库
drop database 'database name';
DROP DATABASE 'database name';
# 选择操作的数据库
use mysql;
USE mysql;
# 创建数据库
CREATE DATABASE 'database name';
@ -122,7 +125,7 @@ CREATE USER 'm23100'@'%';
# 如果要授予该用户对所有数据库和表的相应操作权限则可用 * 表示, 如 *.*
GRANT privileges ON databasename.tablename TO 'username'@'host'
# 示例
GRANT ALL ON test.* to username @ 'localhost' IDENTIFIED BY 'password';
GRANT ALL ON test.* TO username @ 'localhost' IDENTIFIED BY 'password';
# 撤销用户权限
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
@ -136,25 +139,27 @@ sudo systemctl stop mariadb
# 进入安全模式,并设置为后台进程
sudo mysqld_safe --skip-grant-tables &
# 登陆mysql
$ mysql -u root
mariadb -u root
```
```bash
# 查询用户
SELECT Host,User,plugin from mysql.user where User='root';
# 重置加密模式
update mysql.user set plugin='mysql_native_password';
UPDATE mysql.user set plugin='mysql_native_password';
# 重置密码
update mysql.user set password=PASSWORD("newpassword") where User='root';
UPDATE mysql.user set password=PASSWORD("newpassword") where User='root';
# 刷新权限信息
flush privileges;
FLUSH privileges;
exit
```
```bash
# 杀掉进程
kill -9 $(pgrep mysql)
sudo kill -9 $(pgrep mysql)
# 重新启动服务
sudo systemctl start mariadb
# 或
service mariadb start
# 登陆 mysql
mariadb -u root -p

View File

@ -92,7 +92,7 @@ pdbedit -L
通过 systemctl 开启 samba 服务命令如下:
```bash
# Arch Linux
# Manjaro
systemctl enable smb.service
systemctl start smb.service
# Ubuntu