如何安装mysql 5.7.34且修改密码和导入数据
// 首先在终端中查看MySQL的依赖项
sudo dpkg --list|grep mysql
// 卸载在列表中看到的项目
sudo apt-get remove mysql-common
sudo apt-get autoremove --purge mysql-server-5 ##这里的版本写自己安装的
//再次查看MySQL的剩余依赖项
dpkg --list|grep mysql
//用这个删除 rc pc等
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
dpkg -l |grep ^pc|awk '{print $2}' |sudo xargs dpkg -P
//删除失败时,根据提示用语句修复,如:
apt --fix-broken install
//用dpkg -i安装时,需要根据提示按顺序安装mysql的依赖,下面一般最后安装,未按顺序会失败
dpkg -i mysql-community-server_5.7.34-1ubuntu18.04_amd64.deb
//安装好后,查看原始密码
sudo cat /etc/mysql/debian
//仔细看打印信息,其中有密码
mysql -u debian-sys-maint -p
//输入密码
//进入mysql修改密码
use mysql;
update mysql.user set authentication_string=password('root') where user='root';
update mysql.user set authentication_string=PASSWORD('root'), plugin='mysql_native_password' where user='root';
grant all privileges on *.* to 'root'@'%' identified by 'root';
flush privileges;
exit;
//之后exit退出mysql,编辑配置文件
sudo editor /etc/mysql/mysql.conf.d/mysqld.cnf
//将bind-address = 127.0.0.1注释掉(即在行首加#),如下:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
//重启mysql
sudo service mysql start
//进入mysql更新数据库
mysql -uroot -p
use 数据库名;
source ***.sql //导入数据库文件