如何开始MySQL ?

时间:2022-05-20 23:38:34

I locked my root user out from our database. I need to get all privileges back to the root user. I have my password and I can log in to MySQL. But the root user has no all privileges.

我把根用户锁在数据库之外。我需要将所有特权返回给根用户。我有我的密码,我可以登录到MySQL。但是根用户没有所有的特权。

9 个解决方案

#1


33  

I had the same problem as the title of this question, so incase anyone else googles upon this question and wants to start MySql in 'skip-grant-tables' mode on Windows, here is what I did.

我遇到了和这个问题的题目一样的问题,所以如果有人在谷歌上搜索这个问题想要在Windows上启动MySql,这就是我所做的。

Stop the MySQL service through Administrator tools, Services.

通过管理员工具、服务停止MySQL服务。

Modify the my.ini configuration file (assuming default paths)

修改我的。ini配置文件(假设默认路径)

C:\Program Files\MySQL\MySQL Server 5.5\my.ini

or for MySQL version >= 5.6

或者MySQL版本>= 5.6

C:\ProgramData\MySQL\MySQL Server 5.6\my.ini 

In the SERVER SECTION, under [mysqld], add the following line:

在[mysqld]下的SERVER部分中,添加如下一行:

skip-grant-tables

so that you have

所以,你有

# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
[mysqld]

skip-grant-tables

Start the service again and you should be able to log into your database without a password.

重新启动服务,您应该能够在没有密码的情况下登录数据库。

#2


12  

Re-take control of root in MySQL DANGER: RISKY OPERATTION

重新控制根在MySQL危险:危险操作

  • Start session ssh (using root if possible).
  • 启动会话ssh(如果可能的话使用root)。
  • Edit my.cnf file using.

    文件编辑my . cnf中所做。

    sudo vi /etc/my.cnf

    sudo vi /etc/my.cnf

  • Add line to mysqld block.*

    添加到mysqld块中。*。

    skip-grant-tables

    skip-grant-tables

  • Save and exit.

    保存并退出。

  • Restart MySQL service.

    重新启动MySQL服务。

    service mysqld restart

    服务mysqld重启

  • Check service status.

    检查服务状态。

    service mysql status

    mysql服务状态

  • Connect to mysql.

    连接到mysql。

    mysql

    mysql

  • Using main database.

    使用主数据库。

    use mysql;

    使用mysql;

  • Redefine user root password.

    重新定义用户root密码。

    UPDATE user SET authentication_string = PASSWORD('myNuevoPassword') WHERE User = 'root';

    更新用户设置authentication_string = PASSWORD('myNuevoPassword'),其中user = 'root';

  • Edit file my.cnf.

    编辑。文件my . cnf中所做

    sudo vi /etc/my.cnf

    sudo vi /etc/my.cnf

  • Erase line.

    删除线。

    skip-grant-tables

    skip-grant-tables

  • Save and exit.

    保存并退出。

  • Restart MySQL service.

    重新启动MySQL服务。

    service mysqld restart

    服务mysqld重启

  • Check service status.

    检查服务状态。

    service mysql status

    mysql服务状态

  • Connect to database.

    连接到数据库。

    mysql -u root -p

    mysql - u root - p

  • Type new password when prompt.

    在提示时输入新密码。

  • This action is too dangerous, it allows anyone to connect to all databases with no restriction without a user and password. It must be used carefully and MOST be reverted quickly to avoid risks.

    这个操作太危险了,它允许任何人不受用户和密码限制地连接到所有数据库。它必须小心使用,而且要迅速恢复,以避免风险。

#3


2  

If you use mysql 5.6 server and have problems with C:\Program Files\MySQL\MySQL Server 5.6\my.ini:

如果使用mysql 5.6服务器和有C:\Program Files\MySQL\MySQL server 5.6 \ my.ini问题:

You should go to C:\ProgramData\MySQL\MySQL Server 5.6\my.ini.

你应该转到C:\编程式数据\MySQL Server 5.6\my.ini。

You should add skip-grant-tables and then you do not need a password.

您应该添加skip-grant表,然后不需要密码。

# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
# server_type=3
[mysqld]
skip-grant-tables

Note: after you are done with your work on skip-grant-tables, you should restore your file of C:\ProgramData\MySQL\MySQL Server 5.6\my.ini.

注意:完成了对skip-grant表的处理后,应该恢复C:\ProgramData\MySQL Server 5.6\my.ini文件。

#4


2  

if you are running on Apple MacBook OSX then:

如果你正在运行苹果MacBook OSX,那么:

  1. Stop your MySQL server (if it is already running).
  2. 停止MySQL服务器(如果它已经在运行)。
  3. Find your MySQL configuration file, my.cnf. (For me it was placed @ /Applications/XAMPP/xamppfiles/etc. You can just search if you can't find it).
  4. 找到MySQL配置文件my.cnf。(对我来说,它被放置在@ /应用程序/XAMPP/xamppfiles/等等。如果你找不到它,你可以直接搜索。
  5. Open my.cnf file in any text editor.
  6. 在任何文本编辑器中打开my.cnf文件。
  7. Add "skip-grant-tables" (without quotes) at the end of [mysqld] section and save the file.
  8. 在[mysqld]小节末尾添加“skip-grant-tables”(不带引号)并保存文件。
  9. Now start your MySQL server. It'll start with skip-grant-tables option.
  10. 现在启动MySQL服务器。它将从skip-grant-tables选项开始。

Do what you want now!!

现在就做你想做的!!

PS: Please remove skip-grant-tables from my.cnf file once you are done with whatsoever you want to do ELSE MySQL server will always run without access grants.

PS:请从my.cnf文件中删除skip-grant表,一旦您完成了您想做的事情,那么MySQL服务器将始终运行而不授予访问权。

#5


2  

Use the following command (notice the "d"): mysqld --skip-grant-tables

使用以下命令(注意“d”):mysqld—skip-grant-tables

#6


2  

On the Linux system you can do following (Should be similar for other OS)

在Linux系统上,您可以执行以下操作(对于其他操作系统应该类似)

Check if mysql process is running:

检查mysql进程是否正在运行:

sudo service mysql status

If runnning then stop the process: (Make sure you close all mysql tool)

如果运行,那么停止进程:(确保关闭所有mysql工具)

sudo service mysql stop

If you have issue stopping then do following

如果您有问题停止,请执行以下操作

Search for process: ps aux | grep mysqld Kill the process: kill -9 process_id

搜索进程:ps | grep mysqld杀死进程:杀死-9 process_id

Now start mysql in safe mode with skip grant

现在使用skip grant在安全模式下启动mysql

sudo mysqld_safe --skip-grant-tables &

#7


0  

Mysql has a step by step manual for doing this:

Mysql的步骤是这样的:

Reset mysql root password

mysql根密码重置

#8


0  

if this is a windows box, the simplest thing to do is to stop the servers, add skip-grant-tables to the mysql configuration file, and restart the server.

如果这是一个windows box,最简单的方法就是停止服务器,向mysql配置文件添加skip-grant表,然后重新启动服务器。

once you've fixed your permission problems, repeat the above but remove the skip-grant-tables option.

修复了权限问题后,重复上面的操作,但是删除skip-grant-tables选项。

if you don't know where your configuration file is, then log in to mysql send SHOW VARIABLES LIKE '%config%' and one of the rows returned will tell you where your configuration file is.

如果您不知道您的配置文件在哪里,那么登录到mysql发送显示变量,如'%config%',返回的一行将告诉您配置文件在哪里。

#9


0  

Edit my.ini file and add skip-grant-tables and restart your mysql server :

编辑我的。ini文件,添加skip-grant表,重新启动mysql服务器:

[mysqld]
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql" 
tmpdir = "C:/xampp/tmp" 
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"
skip-grant-tables
# Change here for bind listening
# bind-address="127.0.0.1" 
# bind-address = ::1 

#1


33  

I had the same problem as the title of this question, so incase anyone else googles upon this question and wants to start MySql in 'skip-grant-tables' mode on Windows, here is what I did.

我遇到了和这个问题的题目一样的问题,所以如果有人在谷歌上搜索这个问题想要在Windows上启动MySql,这就是我所做的。

Stop the MySQL service through Administrator tools, Services.

通过管理员工具、服务停止MySQL服务。

Modify the my.ini configuration file (assuming default paths)

修改我的。ini配置文件(假设默认路径)

C:\Program Files\MySQL\MySQL Server 5.5\my.ini

or for MySQL version >= 5.6

或者MySQL版本>= 5.6

C:\ProgramData\MySQL\MySQL Server 5.6\my.ini 

In the SERVER SECTION, under [mysqld], add the following line:

在[mysqld]下的SERVER部分中,添加如下一行:

skip-grant-tables

so that you have

所以,你有

# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
[mysqld]

skip-grant-tables

Start the service again and you should be able to log into your database without a password.

重新启动服务,您应该能够在没有密码的情况下登录数据库。

#2


12  

Re-take control of root in MySQL DANGER: RISKY OPERATTION

重新控制根在MySQL危险:危险操作

  • Start session ssh (using root if possible).
  • 启动会话ssh(如果可能的话使用root)。
  • Edit my.cnf file using.

    文件编辑my . cnf中所做。

    sudo vi /etc/my.cnf

    sudo vi /etc/my.cnf

  • Add line to mysqld block.*

    添加到mysqld块中。*。

    skip-grant-tables

    skip-grant-tables

  • Save and exit.

    保存并退出。

  • Restart MySQL service.

    重新启动MySQL服务。

    service mysqld restart

    服务mysqld重启

  • Check service status.

    检查服务状态。

    service mysql status

    mysql服务状态

  • Connect to mysql.

    连接到mysql。

    mysql

    mysql

  • Using main database.

    使用主数据库。

    use mysql;

    使用mysql;

  • Redefine user root password.

    重新定义用户root密码。

    UPDATE user SET authentication_string = PASSWORD('myNuevoPassword') WHERE User = 'root';

    更新用户设置authentication_string = PASSWORD('myNuevoPassword'),其中user = 'root';

  • Edit file my.cnf.

    编辑。文件my . cnf中所做

    sudo vi /etc/my.cnf

    sudo vi /etc/my.cnf

  • Erase line.

    删除线。

    skip-grant-tables

    skip-grant-tables

  • Save and exit.

    保存并退出。

  • Restart MySQL service.

    重新启动MySQL服务。

    service mysqld restart

    服务mysqld重启

  • Check service status.

    检查服务状态。

    service mysql status

    mysql服务状态

  • Connect to database.

    连接到数据库。

    mysql -u root -p

    mysql - u root - p

  • Type new password when prompt.

    在提示时输入新密码。

  • This action is too dangerous, it allows anyone to connect to all databases with no restriction without a user and password. It must be used carefully and MOST be reverted quickly to avoid risks.

    这个操作太危险了,它允许任何人不受用户和密码限制地连接到所有数据库。它必须小心使用,而且要迅速恢复,以避免风险。

#3


2  

If you use mysql 5.6 server and have problems with C:\Program Files\MySQL\MySQL Server 5.6\my.ini:

如果使用mysql 5.6服务器和有C:\Program Files\MySQL\MySQL server 5.6 \ my.ini问题:

You should go to C:\ProgramData\MySQL\MySQL Server 5.6\my.ini.

你应该转到C:\编程式数据\MySQL Server 5.6\my.ini。

You should add skip-grant-tables and then you do not need a password.

您应该添加skip-grant表,然后不需要密码。

# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
# server_type=3
[mysqld]
skip-grant-tables

Note: after you are done with your work on skip-grant-tables, you should restore your file of C:\ProgramData\MySQL\MySQL Server 5.6\my.ini.

注意:完成了对skip-grant表的处理后,应该恢复C:\ProgramData\MySQL Server 5.6\my.ini文件。

#4


2  

if you are running on Apple MacBook OSX then:

如果你正在运行苹果MacBook OSX,那么:

  1. Stop your MySQL server (if it is already running).
  2. 停止MySQL服务器(如果它已经在运行)。
  3. Find your MySQL configuration file, my.cnf. (For me it was placed @ /Applications/XAMPP/xamppfiles/etc. You can just search if you can't find it).
  4. 找到MySQL配置文件my.cnf。(对我来说,它被放置在@ /应用程序/XAMPP/xamppfiles/等等。如果你找不到它,你可以直接搜索。
  5. Open my.cnf file in any text editor.
  6. 在任何文本编辑器中打开my.cnf文件。
  7. Add "skip-grant-tables" (without quotes) at the end of [mysqld] section and save the file.
  8. 在[mysqld]小节末尾添加“skip-grant-tables”(不带引号)并保存文件。
  9. Now start your MySQL server. It'll start with skip-grant-tables option.
  10. 现在启动MySQL服务器。它将从skip-grant-tables选项开始。

Do what you want now!!

现在就做你想做的!!

PS: Please remove skip-grant-tables from my.cnf file once you are done with whatsoever you want to do ELSE MySQL server will always run without access grants.

PS:请从my.cnf文件中删除skip-grant表,一旦您完成了您想做的事情,那么MySQL服务器将始终运行而不授予访问权。

#5


2  

Use the following command (notice the "d"): mysqld --skip-grant-tables

使用以下命令(注意“d”):mysqld—skip-grant-tables

#6


2  

On the Linux system you can do following (Should be similar for other OS)

在Linux系统上,您可以执行以下操作(对于其他操作系统应该类似)

Check if mysql process is running:

检查mysql进程是否正在运行:

sudo service mysql status

If runnning then stop the process: (Make sure you close all mysql tool)

如果运行,那么停止进程:(确保关闭所有mysql工具)

sudo service mysql stop

If you have issue stopping then do following

如果您有问题停止,请执行以下操作

Search for process: ps aux | grep mysqld Kill the process: kill -9 process_id

搜索进程:ps | grep mysqld杀死进程:杀死-9 process_id

Now start mysql in safe mode with skip grant

现在使用skip grant在安全模式下启动mysql

sudo mysqld_safe --skip-grant-tables &

#7


0  

Mysql has a step by step manual for doing this:

Mysql的步骤是这样的:

Reset mysql root password

mysql根密码重置

#8


0  

if this is a windows box, the simplest thing to do is to stop the servers, add skip-grant-tables to the mysql configuration file, and restart the server.

如果这是一个windows box,最简单的方法就是停止服务器,向mysql配置文件添加skip-grant表,然后重新启动服务器。

once you've fixed your permission problems, repeat the above but remove the skip-grant-tables option.

修复了权限问题后,重复上面的操作,但是删除skip-grant-tables选项。

if you don't know where your configuration file is, then log in to mysql send SHOW VARIABLES LIKE '%config%' and one of the rows returned will tell you where your configuration file is.

如果您不知道您的配置文件在哪里,那么登录到mysql发送显示变量,如'%config%',返回的一行将告诉您配置文件在哪里。

#9


0  

Edit my.ini file and add skip-grant-tables and restart your mysql server :

编辑我的。ini文件,添加skip-grant表,重新启动mysql服务器:

[mysqld]
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql" 
tmpdir = "C:/xampp/tmp" 
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"
skip-grant-tables
# Change here for bind listening
# bind-address="127.0.0.1" 
# bind-address = ::1