mysql遇到的坑_迁移Mysql遇到的坑

最近在做些机器的迁移,其中就包括Mysql数据库的迁移,在迁移的过程中遇到一个坑,在这里和大家分享一下。我们使用的Mysql的版本是5.6,我将老的机器上的Mysql 5.6 的安装包直接拷贝到新的机器上安装好,并将相应配置文件也拷贝到了新机器上,使用了相同的命令启动Mysql服务结果报错了。报错内容如下:

Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

于是通过该关键字google了一下,得知Mysql初次启动的时候需要初始化data 目录,从而新建一些系统表。

As suggested above, i had similar issue with mysql-5.7.18,

i did this in this way

1. Executed this command from "MYSQL_HOME\bin\mysqld.exe --initialize-insecure"

2. then started "MYSQL_HOME\bin\mysqld.exe"

3. Connect workbench to this localhost:3306 with username 'root'

4. then executed this query "SET PASSWORD FOR 'root'@'localhost' = 'root';"

password was also updated successfully.

于是我就按照上面的步骤进行data 目录的初始化,结果在第一步就报错了,unknown option --initialize-insecure, 经过查询得知我忽略了mysql 的版本号,5.7版本之后是可以通过 --initialize-insecure 进行data目录的初始化,但是5.6 版本并不支持这个参数,于是就去查了一下5.6的官方文档。其中提到了一个在Linux下初始化Data目录的方法,并没有windows系统下初始化data目录的方法。

1.Change location to the top-level directory of your MySQL installation, which is typically /usr/local/mysql (adjust the path name for your system as necessary):

cd /usr/local/mysql

2. You will find several files and subdirectories inside the directory, including the bin and scripts subdirectories, which contain the server as well as client and utility programs.Initialize the data directory, including the mysql database containing the initial MySQL grant tables that determine how users are permitted to connect to the server. For example:

scripts/mysql_install_db --user=mysql

我还特意到安装目录下找了一下这个scripts目录结果没找到,但是在安装目录下找到了一个data目录,该目录下有两个文件夹:

6e4804472cab

image.png

通过这两个目录在联想到之前报错信息,我确认这应该就是mysql默认的系统表,于是我将该data目录下的所有文件拷贝到我配置的data目录下,然后启动mysql服务,直接成功了。折腾这么久结果需要的东西正好在安装目录下,不过通过这次踩坑,对mysql在windows下的安装和启动有了更深的了解。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值