MySQL installation common problems (the system cannot find the specified file, system error 1067 occurs, the process terminates unexpectedly)

There are always problems of this kind when installing mysql, and each reinstallation will take a lot of time to troubleshoot. In fact, there are many related articles on the Internet, but many of them only talk about the method, but do not talk about the specific details, which leads to the inability to solve the problem. In fact, sometimes I know the cause of the problem, but I don't notice it because of some details. Repeated attempts waste a lot of time. Now record the problems I encountered during the installation and the problems that I should pay attention to.

Environment: windows7

mysql version: mysql-5.6.10-win32

If it is installed by default, then mysql will be installed in the directory C:\Program Files\MySQL\MySQL Server 5.6, pay special attention to this directory, and the reason will be explained below.

Under normal circumstances, after installing mysql, we all hope that we can connect and use it directly, but the actual situation may not be so smooth. After the installation is complete, enter the command directly in CMD:

  1. C:\Windows\system32>mysql -uroot  
  2. 'mysql' is not an internal or external command, nor is it a runnable program or batch file.  

 

 

This is caused by not configuring environment variables. Of course, you can also switch to the installation directory of mysql before executing the command, but isn't that troublesome?

First configure the environment variables, and add the bin directory of the directory where mysql is located to the path environment variable (the specific operation of how to set the environment variable is omitted, you can google a lot).

 

After configuring the environment variables, should you be able to connect to mysql? Try mysql -uroot, hey, what's going on:

  1. C:\Windows\system32>mysql -uroot  
  2. ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)  

 

 

what reason? Is the service not started, let's start the service and see:

  1. C:\Windows\system32>net start mysql  
  2. The service name is invalid.  
  3.   
  4. Please type NET HELPMSG 2185 for more help.  

 

 

居然服务名无效?打开windows服务一看,原来是安装完mysql后根本没有安装mysql服务,需要我们手动安装。

安装mysql的服务很“简单”,在命令行中输入:

  1. C:\Users\MikanMu>mysqld --install  
  2. Install/Remove of the Service Denied!  

 

 

咦,怎么回事?这是由于没有权限造成的,需要在启动命令行时以管理员身份运行才行。关闭当前cmd窗口重新以管理员身份运行:

  1. C:\Windows\system32>mysqld --install  
  2. Service successfully installed.  

 

 

提示成功安装。很好,安装完服务后,启动起来看看:

  1. C:\Windows\system32>net start mysql  
  2. 发生系统错误 2。  
  3.   
  4. 系统找不到指定的文件。  

 

 

我了个去,这又是怎么回事?上网各种查,都说是需要在mysql配置文件中添加路径:

basedir=C:/Program Files/MySQL/MySQL Server 5.6
datadir=C:/Program Files/MySQL/MySQL Server 5.6/data

 

好吧,我试试,mysql-5.6.10-win32默认的配置文件是在C:/Program Files/MySQL/MySQL Server 5.6/my-default.ini,或者自己建立一个my.ini文件,在其中添加配置:

[mysqld]
basedir=C:/Program Files/MySQL/MySQL Server 5.6
datadir=C:/Program Files/MySQL/MySQL Server 5.6/data

 

注意:1、安装目录下由于权限的原因不能直接建立文件,需要在其他地方建立并添加好相应的配置后,再拷贝到安装目录C:/Program Files/MySQL/MySQL Server 5.6下。

2、网上有的说配置中的目录分隔符必须是正斜杠‘/’,但是经过实验,‘/’、‘\’、‘\\’都没有问题,都是可以的。

3、basedir这个配置是mysql的安装目录,记住,一定是要配置到C:/Program Files/MySQL/MySQL Server 5.6这个目录,不能到C:/Program Files/MySQL就完了。

4、my.ini文件的编码必须是英文编码(如windows中的ANSI),不能是UTF-8或GBK等。

上面操作完成后(一定要注意细节),再来启动一下服务:

  1. C:\Windows\system32>net start mysql  
  2. 发生系统错误 2。  
  3.   
  4.   
  5. 系统找不到指定的文件。  

 

 

怎么还是报这个错?难道不是由于配置的原因?对,不是由于上面的配置的问题,但上面的配置添加后也没有错。那是什么原因?

这里是最需要注意的地方,在安装mysql服务时,一定要切换到mysql安装目录的bin目录下,不管你是否配置环境变量,否则在安装完后启动服务还是会报上面的错误。

切换到bin目录后,先删除前面安装的mysql服务(删除服务不一定要到bin目录),再重新在bin目录下安装mysql服务,然后启动:

  1. C:\Windows\system32>cd ../..  
  2.   
  3. C:\>cd Program Files\MySQL\MySQL Server 5.6\bin  
  4.   
  5. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --remove  
  6. Service successfully removed.  
  7.   
  8. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --install  
  9. Service successfully installed.  
  10.   
  11. C:\Program Files\MySQL\MySQL Server 5.6\bin>net start mysql  
  12. MySQL 服务正在启动 .  
  13. MySQL 服务已经启动成功。  


哇,终于成功了!!

 

现在来验证一下不需要添加my.ini文件,也是可以正常启动服务的,只要是在bin目录下安装的服务就行。只需要停止mysql服务,把服务删除后,再把mysql安装目录下的my.ini文件删除掉,再重新安装服务,启动mysql服务,看看能不能正常启动即可,实验证明,是可以正常启动的。

  1. C:\Program Files\MySQL\MySQL Server 5.6\bin>net stop mysql  
  2. MySQL 服务正在停止.  
  3. MySQL 服务已成功停止。  
  4.   
  5. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --remove  
  6. Service successfully removed.  
  7.   
  8. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --install  
  9. Service successfully installed.  
  10.   
  11. C:\Program Files\MySQL\MySQL Server 5.6\bin>net start mysql  
  12. MySQL 服务正在启动 .  
  13. MySQL 服务已经启动成功。  

 

 

终于大功告成!!!看看能不能连接:

  1. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -uroot  
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  3. Your MySQL connection id is 3  
  4. Server version: 5.6.10 MySQL Community Server (GPL)  
  5.   
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.  
  7.   
  8. Oracle is a registered trademark of Oracle Corporation and/or its  
  9. affiliates. Other names may be trademarks of their respective  
  10. owners.  
  11.   
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  13.   
  14. mysql>  

 

 

完全没有问题。

 

另外,mysql默认的root用户是没有设置密码的,我们可以修改root用户密码,方法如下:

1、直接在cmd命令行,不需要进入mysql

 

  1. mysqladmin -u root password '新密码'  

 

 

2、在mysql中,一定要连接到某个数据库

  1. mysql> use mysql  
  2. Database changed  
  3. mysql> update user set password=password('新密码') where user='root';  
  4. Query OK, 3 rows affected (0.00 sec)  
  5. Rows matched: 3  Changed: 3  Warnings: 0  
  6.   
  7. mysql> flush privileges;  
  8. Query OK, 0 rows affected (0.00 sec)  

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326990459&siteId=291194637