环境介绍
一些使用方法
使用的是 Deepin 15.7 版本
内核使用
Linux l–PC 4.15.0-29deepin-generic #31 SMP Fri Jul 27 07:12:08 UTC 2018 x86_64 GNU/Linux
使用的mysql版本是
mysql 5.7.21
安装
安装mysql服务
sudo apt -y install mariadb-server
sudo apt install -y mariadb-client
启动与关闭
源码安装的可以在linux运行程序中看
ps -ef |grep mysql
apt安装的查看状态
service mysql status
启动mysql
sudo service mysql start
关闭
sudo service mysql stop
登录mysql
新安装好的mysql密码为空,你需要设置一个密码,或者初始化。
初始化
sudo mysql_secure_installation
要是看不懂可以看看
用户管理
创建用户
第一种方法(我最喜欢这种)
创建一个叫‘newuser’密码‘123456’的本地用户
MariaDB [mysql]> create user newuser@localhost identified by '123456';
第二种方法
创建一个叫‘chenshaohua’密码‘1234’的本地用户
MariaDB [(none)]> insert into mysql.user(user,host,password) values('chenshaohua','localhost',password('1234'));
授权
创建一个叫‘liudehua’密码‘123456’的本地用户,同时授予全部权限
MariaDB [(none)]> grant all privileges on *.* to liudehua@localhost identified by '123456';
指定部分权限
MariaDB [(none)]> grant insert,update,delete,select,create,drop on *.* to mytest@localhost;
命令 | 作用 |
---|---|
select | 查看 |
insert | 插入 |
update | 修改 |
delete | 删除 |
create | 创建 |
drop | 删除 |
查看用户权限
MariaDB [(none)]> show grants for liudehua@localhost;
保存与回复
备份保存
语法
命令 mysqldump + 用户 + 密码 + 数据库名称 > 保存位置(最后用.sql结尾方便查看)
/usr/local/mysql/bin/mysqldump -uroot -p data_name > /home/name.sql
或者
mysqldump -uroot -p data_name > /home/name.sql
数据恢复
语法
方案一
MariaDB [(none)]> create database renwole; //建立空数据库名
MariaDB [(none)]> use renwole; //选择数据库
MariaDB [(none)]> set names utf8; //设置数据库导入编码
MariaDB [(none)]> source /home/renwole.sql; //导入数据(注意sql文件的路径)
方案二
mysql -uroot -p renwole < /home/renwole.sql
建议使用第二种方案导入,简单快捷不用设置导入编码,不易出错。以上解决方案也适用于mysql&mariadb任意版本