数据库升级


1.下载数据库版本自己选 https://dev.mysql.com/downloads/mysql/5.7.html 2.备份服务器数据库 //备份全部数据库 mysqldump --all-databases -h127.0.0.1 -uroot -ppass > allbackupfile.sql //备份单个或多个数据库 mysqldump -h127.0.0.1 -uroot -ppass myweb * * > backupfile.sql 备份遇到问题 Access denied for user 'root'@'localhost' to database 'information_schema' when using LOCK TABLES   mysqldump: Error 1194: Table 'desktop_document2' is marked as crashed and should be repaired when dumping table `desktop_document2` at row: 10602 1、进入数据库对该表进行检测:(先 use db) check tables desktop_document2; 2、使用repair解决方法 repair table *; 3.上传tar包并解压到数据库安装路径(/usr/local/) 4.删除mysql软连接 rm -rf mysql 5.软连接新的版本数据库路径 ln -fs mysql-*** mysql 6.创建data目录 mkdir data 7.删除my.cnf(可不删除) 8.初始化安装mysql1(修改路径) bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.28/ --datadir=/usr/local/mysql-5.7.28/data/ 9.更改所属的组和用户 chown -R mysql:mysql mysql 10.启动mysql(修改路径 /usr/local/mysql-5.7.28/bin/mysqld_safe --user=mysql & 11.bin路径下登录mysql,密码vi /etc/my.cnf 在第二行增加:skip-grant-tables 保存并退出(:wq) 12.重启mysql2 service mysqld restart 错误 Starting MySQL...The server quit without updating PID file [失败]local/mysql/data/master.pid). 从原数据库路径scp并授权mysql:mysql 13.修改密码 bin路径执行,直接回车 ./mysql -u root -p update user set authentication_string=password('123456') where user='root'; flush privileges;  quit; 14.修改my.cnf配置,去掉skip-grant-tables 保存并退出(:wq) 15.重启mysql :service mysqld restart; ./mysql mysql -u root -p 进入 16.修改权限 use mysql; grant all privileges on *.* to root@"%" identified by "123456"; flush privileges;  quit; 错误 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. SET PASSWORD = PASSWORD('123456'); 17.还原备份数据库 系统命令行: mysqladmin -uroot -p123456 create db_name mysql -uroot -p123456  db_name < d:\bak\0101.sql   注:在导入备份数据库前,db_name如果没有,是需要创建的; 而且与backup20110527.sql中数据库名是一样的才可以导入。 2. soure 方法: mysql > use db mysql > source d:\bak\0101.sql 参考链接 https://blog.csdn.net/qq_40198004/article/details/102759645