情况介绍:在云上划拉一块地方建立本地数据库测试环境,通过数据库备份包恢复数据并启动。
1.在云上或者你自己的server上安装Percona Server for MySQL,步骤如下
Use APT repositories - Percona Server for MySQL
How to Install or Upgrade Percona Server for MySQL/MySQL 8 to a Specific Version on Debian/Ubuntu
$ sudo apt update
$ sudo apt install curl
$ curl -O https://repo.percona.com/apt/percona-release_latest.generic_all.deb
$ sudo apt install gnupg2 lsb-release ./percona-release_latest.generic_all.deb
$ sudo apt update
$ sudo percona-release setup ps80
$ sudo apt install percona-server-server
#这时输入mysql就能进入了,如果想安装指定的版本,可以用以下命令$ sudo percona-release setup ps80
$ sudo apt list -a percona-server-server
$ sudo apt install percona-server-server=8.0.28-20-1.bullseye percona-server-common=8.0.28-20-1.bullseye percona-server-client=8.0.28-20-1.bullseye
2.想办法把生产环境的数据库拷贝到这台server上
3.检查一下自己的my.cnf文件,修改datadir为你的备份的文件目录,一般在/etc/my.cnf这个目录,如果找不到可以执行这个下面的命令,然后到输出来的路径里找找看。
$ /usr/sbin/mysqld --help --verbose | grep -A1 'Default options are read from the following files in the given order'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
你会找到一个类似这样的文件
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
然后用你之前的用户名密码就可以登录了,如果不能登录又不知道密码可以试试“--skip-grant-tables”方式,这样开启服务
$/etc/init.d/mysql start --skip-grant-tables
如果还是不行可以把“skip_grant_tables”加入你自己的my.cnf或者类似的文件里,就是包含datadir路径的文件,然后重启就可以免密登进mysql>了
4.修改密码
如果是通过“skip_grant_tables”进去mysql>的可以用这个方式:
mysql登录报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) - 向前走。 - 博客园 (cnblogs.com)
因为这种情况下想修改密码或者创建用户的时候都会出现如下错误
mysql> ALTER USER IF EXISTS 'root'@'localhost' IDENTIFIED BY '123%' PASSWORD EXPIRE NEVER;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
上面文章中建议输入flush privileges;我试过了,可以,进去后给自己建个账号和新密码。
mysql> CREATE USER 'your_username'@'%' IDENTIFIED BY 'your_password'; #创建用户your_username
mysql> GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;mysql>ALTER USER 'your_username'@'%' IDENTIFIED WITH mysql_native_password BY 'your_password'; #这里更新一下密码
mysql> FLUSH PRIVILEGES; #刷新权限
然后就可以用你喜欢的工具链接这个数据库啦。Bye