修正 MariaDB 操作中的一些问题.
Signed-off-by: chen.yang <chen.yang@yuzhen-iot.com>
This commit is contained in:
parent
ba5ad79394
commit
7bf0a7e958
|
@ -16,7 +16,7 @@ published: true
|
||||||
```bash
|
```bash
|
||||||
# Ubuntu
|
# Ubuntu
|
||||||
apt install docker.io
|
apt install docker.io
|
||||||
# Arch Linux/Manjaro
|
# Manjaro
|
||||||
pacman -S docker
|
pacman -S docker
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,10 @@ MariaDB 是与 MySQL 兼容的开源实现,当 Linux 服务器上需要使用
|
||||||
MariaDB 的安装命令如下:
|
MariaDB 的安装命令如下:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
## Arch Linux
|
# Manjaro
|
||||||
pacman -S mariadb mariadb-clients mariadb-libs
|
sudo pacman -S mariadb mariadb-clients mariadb-libs
|
||||||
## Ubuntu
|
# Ubuntu
|
||||||
apt install mariadb-server mariadb-client libmariadb-dev libmariadbclient-dev
|
sudo apt install mariadb-server mariadb-client libmariadb-dev libmariadbclient-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
## 2.初始配置
|
## 2.初始配置
|
||||||
|
@ -18,13 +18,16 @@ apt install mariadb-server mariadb-client libmariadb-dev libmariadbclient-dev
|
||||||
安装完 MariaDB 后需要进行初始配置,首先需要执行以下命令:
|
安装完 MariaDB 后需要进行初始配置,首先需要执行以下命令:
|
||||||
|
|
||||||
```bash
|
```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 的系统服务:
|
之后启动 MariaDB 的系统服务:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
systemctl start mariadb
|
sudo systemctl start mariadb
|
||||||
```
|
```
|
||||||
|
|
||||||
最后初始化数据库:
|
最后初始化数据库:
|
||||||
|
@ -53,9 +56,9 @@ mariadb -u root -p
|
||||||
mariadb -h localhost -u root -p
|
mariadb -h localhost -u root -p
|
||||||
|
|
||||||
# 更改密码(解决普通用户登陆报错:Access denied for user 'root'@'localhost'),请将'passwd'替换为实际的密码
|
# 更改密码(解决普通用户登陆报错: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;
|
FLUSH privileges;
|
||||||
|
@ -76,13 +79,13 @@ SHOW global variables like 'port';
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 显示所有数据库
|
# 显示所有数据库
|
||||||
SHOW databases;
|
SHOW DATABASES;
|
||||||
|
|
||||||
# 删除数据库
|
# 删除数据库
|
||||||
drop database 'database name';
|
DROP DATABASE 'database name';
|
||||||
|
|
||||||
# 选择操作的数据库
|
# 选择操作的数据库
|
||||||
use mysql;
|
USE mysql;
|
||||||
|
|
||||||
# 创建数据库
|
# 创建数据库
|
||||||
CREATE DATABASE 'database name';
|
CREATE DATABASE 'database name';
|
||||||
|
@ -122,7 +125,7 @@ CREATE USER 'm23100'@'%';
|
||||||
# 如果要授予该用户对所有数据库和表的相应操作权限则可用 * 表示, 如 *.*
|
# 如果要授予该用户对所有数据库和表的相应操作权限则可用 * 表示, 如 *.*
|
||||||
GRANT privileges ON databasename.tablename TO 'username'@'host'
|
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';
|
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
|
||||||
|
@ -136,25 +139,27 @@ sudo systemctl stop mariadb
|
||||||
# 进入安全模式,并设置为后台进程
|
# 进入安全模式,并设置为后台进程
|
||||||
sudo mysqld_safe --skip-grant-tables &
|
sudo mysqld_safe --skip-grant-tables &
|
||||||
# 登陆mysql
|
# 登陆mysql
|
||||||
$ mysql -u root
|
mariadb -u root
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 查询用户
|
# 查询用户
|
||||||
SELECT Host,User,plugin from mysql.user where User='root';
|
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
|
exit
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 杀掉进程
|
# 杀掉进程
|
||||||
kill -9 $(pgrep mysql)
|
sudo kill -9 $(pgrep mysql)
|
||||||
# 重新启动服务
|
# 重新启动服务
|
||||||
|
sudo systemctl start mariadb
|
||||||
|
# 或
|
||||||
service mariadb start
|
service mariadb start
|
||||||
# 登陆 mysql
|
# 登陆 mysql
|
||||||
mariadb -u root -p
|
mariadb -u root -p
|
||||||
|
|
|
@ -92,7 +92,7 @@ pdbedit -L
|
||||||
通过 systemctl 开启 samba 服务命令如下:
|
通过 systemctl 开启 samba 服务命令如下:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Arch Linux
|
# Manjaro
|
||||||
systemctl enable smb.service
|
systemctl enable smb.service
|
||||||
systemctl start smb.service
|
systemctl start smb.service
|
||||||
# Ubuntu
|
# Ubuntu
|
||||||
|
|
Loading…
Reference in New Issue