习惯使用LAMP建站,所以需要自己建立用户和数据库,网站使用本地连接就可以了。注意mysql语句末尾有个分号;
登录数据库
mysql -u root -p
添加新用户
允许本地 IP 访问 localhost, 127.0.0.1
create user 'test'@'localhost' identified by '123456';
允许外网 IP 访问 将localhost替换成%
create user 'test'@'%' identified by '123456';
修改test密码为12345678
update user set password=password("12345678") where user="test";
刷新授权
flush privileges;
查看所有用户
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
查看用户权限
show grants for test;
查看数据库
show databases;
删除用户
drop user [email protected]'%';
删除数据库
drop database testdb;
为用户创建数据库
create database testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
为新用户分配权限
授予用户在本地服务器对该数据库的全部权限
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';
授予用户在本地服务器的最高权限
grant all privileges on *.* to 'test'@'localhost' identified by '123456' with grant option;
授予用户通过外网IP对于该数据库的全部权限
grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';
刷新权限
flush privileges;
选择数据库
use testdb;
备份数据库
mysqldump -uroot -p --all-databases >/tmp/all.sql
排除指定数据库备份
mysql -e "show databases;" -ugame -p| grep -Ev "Database|information_schema|mysql|phpmyadmin" | xargs mysqldump -ugame -p --databases > mysql_dump.sql
从本地导入数据库
source ~/temp/testdb.sql
退出 root 登录
\q
滴!小编卡!打卡时间:下午8:01:32,请上车的乘客系好安全带~