1、忘记密码并更改密码
首先想办法进入mysql
cd /etc/mysql
cat debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = A33m4rc4oLgY06Gj
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = A33m4rc4oLgY06Gj
socket = /var/run/mysqld/mysqld.sock
mysql -u debian-sys-maint -p
输入密码:A33m4rc4oLgY06Gj
这样就进入了mysql,之后执行
USE mysql;
SHOW fields FROM user; 或者(describe user;)
目的是查看密码在mysql中的字段,要么为password,要么为authentication_string,有哪个用哪个,下面更改密码:
UPDATE mysql.user SET authentication_string=PASSWORD('123456') where USER='root';
更新:
flush privileges;
参考:https://blog.csdn.net/skh2015java/article/details/80156278、https://blog.csdn.net/li_computer_vision/article/details/100055606
2、远程登录
cd /etc/mysql/mysql.conf.d
vim mysqld.cnf
注释掉bind 127.0.0.1
方法1:授权
mysql -u root -p
输入密码:123456
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
flush privileges;
方法2:修改表的值
mysql -u root -p
use mysql;
select host,user from user where user=root;
# 如果上面查询到有信息,但host为localhost或其他值,就需要根据实际需求来更新表信息
update user set host='%' where user='root'
参考:https://www.cnblogs.com/xiaoQ0725/p/8535735.html
service mysql restart
参考:https://blog.csdn.net/qq_43125439/article/details/83745956
3、数据库导入
登陆mysql:
mysql -u root -p
CREATE database test;
USE test;
导入:
source /home/test.sql;
参考:https://www.cnblogs.com/duanyingkui/p/8336060.html
4、数据库导出
导出本机mysql的数据库:
mysqldump -u root -p test > /home/test.sql
导出其他机器上mysql的数据库:
mysqldump -h 192.168.x.xxx -u root -p test > /home/test.sql