Mysql default root password windows

How to change MySQL root password to default?

My initial installation for the MySQL had no password for root. I assigned a password for root and everything worked fine. Due to some reason (don’t ask why) I had to revert back to the original settings where root didn’t have any password.

I changed the root password to » (empty string) . The problem now is that MySQL doesn’t run with ‘mysql -uroot’ , it expects a password. On running ‘mysql -uroot -p’ and hitting enter on the password prompt gets me into the db, but is not same as the default setting.

Is there any other flag/setting that I am missing to set/unset which tells mysql to not expect a password?

2 Answers 2

How to Reset MySQL root password:

To reset it, see How to Reset the Root Password in the MySQL manual.

How to run MySQL without password controlled access

To run MySQL with the password controls disabled, check out the —skip-grant-tables option.

How to avoid typing credentials on the command line

If you simply want to avoid having to type the password on the mysql command line, create a file called .my.cnf (note leading period on that filename!) in your home directory. In your case, for the root user, probably /root

Add the following entries to the file

You’d typically chmod 600 this file so that only you can see it, and MySQL will ignore a .my.cnf which is world writable anyway.

See the manual page Using Option Files for more information

Information Security Squad

stay tune stay secure

  • Home
  • 2019
  • Октябрь
  • 29
  • 👥 Как сбросить пароль root в MySQL 8.0 в Windows

👥 Как сбросить пароль root в MySQL 8.0 в Windows

Если вы предварительно установили пароль root, но забыли его, вы можете установить новый пароль.

Следующая процедура подойдет только для систем Windows.

Вы должны войти в Windows как пользователь с правами администратора, затем выполните следующие действия:

1. Остановите сервер MySQL, если он работает.

Для сервера, работающего в качестве службы Windows, перейдите в диспетчер служб:

Параметр –skip-grant-tables пропустит чтение таблиц разрешений для MySQL Server; это позволит любому пользователю подключаться без использования пароля с полным доступом ко всем таблицам.

Дополнительный параметр –skip-network снижает риск безопасности, не позволяя серверу принимать соединения через TCP / IP; вместо этого включаются именованные каналы с помощью –enabled-named-pipe.

Именованные каналы доступны только в системах на базе NT, поэтому TCP / IP должен использоваться для других ОС Windows.

Если вы беспокоитесь о безопасности, вы должны использовать брандмауэр для блокировки внешнего доступа к серверу в течение этого времени.

Оставив первое окно консоли открытым, откройте второе окно консоли и выполните следующие команды (введите каждую в одной строке):

Замените «newpwd» фактическим паролем рута, который вы хотите использовать.

Вторая команда предложит вам ввести новый пароль для доступа.

Введите пароль, который вы указали в первой команде.

Как только вы остановили сервер MySQL, снова перезапустите его в обычном режиме.

Если вы запускаете сервер как службу, вы можете запустить его из окна Windows служб.

Если вы запускаете сервер вручную, используйте любую команду, которую вы обычно используете.

Теперь вы сможете подключиться, используя новый пароль root.

Один из способов сброса пароля root в Windows – выполнить процедуру, указанную в руководстве по ссылке ниже.

Mysql default root password windows

If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root . However, this is insecure. For instructions on assigning a password, see Section 2.10.4, “Securing the Initial MySQL Account”.

Читайте также:  Обновление для windows иконки

If you assigned a root password previously but have forgotten it, you can assign a new password. The following sections provide instructions for Windows and Unix and Unix-like systems, as well as generic instructions that apply to any system.

B.3.3.2.1 Resetting the Root Password: Windows Systems

On Windows, use the following procedure to reset the password for the MySQL ‘root’@’localhost’ account. To change the password for a root account with a different host name part, modify the instructions to use that host name.

Log on to your system as Administrator.

Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel , then Administrative Tools , then Services . Find the MySQL service in the list and stop it.

If your server is not running as a service, you may need to use the Task Manager to force it to stop.

Create a text file containing the password-assignment statement on a single line. Replace the password with the password that you want to use.

Save the file. This example assumes that you name the file C:\mysql-init.txt .

Open a console window to get to the command prompt: From the Start menu, select Run , then enter cmd as the command to be run.

Start the MySQL server with the init_file system variable set to name the file (notice that the backslash in the option value is doubled):

If you installed MySQL to a different location, adjust the cd command accordingly.

The server executes the contents of the file named by the init_file system variable at startup, changing the ‘root’@’localhost’ account password.

To have server output to appear in the console window rather than in a log file, add the —console option to the mysqld command.

If you installed MySQL using the MySQL Installation Wizard, you may need to specify a —defaults-file option. For example:

The appropriate —defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel , then Administrative Tools , then Services . Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the —defaults-file setting.

After the server has started successfully, delete C:\mysql-init.txt .

You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server and restart it normally. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.

B.3.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems

On Unix, use the following procedure to reset the password for the MySQL ‘root’@’localhost’ account. To change the password for a root account with a different host name part, modify the instructions to use that host name.

The instructions assume that you start the MySQL server from the Unix login account that you normally use for running it. For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root , but in this case you must start mysqld with the —user=mysql option. If you start the server as root without using —user=mysql , the server may create root -owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups. If that happens, you must either change the ownership of the files to mysql or remove them.

Log on to your system as the Unix user that the MySQL server runs as (for example, mysql ).

Читайте также:  Как посмотреть свою группу linux

Stop the MySQL server if it is running. Locate the .pid file that contains the server’s process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/ , /var/run/mysqld/ , and /usr/local/mysql/data/ . Generally, the file name has an extension of .pid and begins with either mysqld or your system’s host name.

Stop the MySQL server by sending a normal kill (not kill -9 ) to the mysqld process. Use the actual path name of the .pid file in the following command:

Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.

Create a text file containing the password-assignment statement on a single line. Replace the password with the password that you want to use.

Save the file. This example assumes that you name the file /home/me/mysql-init . The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.

Start the MySQL server with the init_file system variable set to name the file:

The server executes the contents of the file named by the init_file system variable at startup, changing the ‘root’@’localhost’ account password.

Other options may be necessary as well, depending on how you normally start your server. For example, —defaults-file may be needed before the init_file argument.

After the server has started successfully, delete /home/me/mysql-init .

You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.

B.3.3.2.3 Resetting the Root Password: Generic Instructions

The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure):

Stop the MySQL server if necessary, then restart it with the —skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD . Because this is insecure, if the server is started with the —skip-grant-tables option, it also disables remote connections by enabling skip_networking .

Connect to the MySQL server using the mysql client; no password is necessary because the server was started with —skip-grant-tables :

In the mysql client, tell the server to reload the grant tables so that account-management statements work:

Then change the ‘root’@’localhost’ account password. Replace the password with the password that you want to use. To change the password for a root account with a different host name part, modify the instructions to use that host name.

You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the —skip-grant-tables option and without enabling the skip_networking system variable).

Chapter 4 Resetting the Root Password: Windows Systems

On Windows, use the following procedure to reset the password for the MySQL ‘root’@’localhost’ account. To change the password for a root account with a different host name part, modify the instructions to use that host name.

Log on to your system as Administrator.

Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel , then Administrative Tools , then Services . Find the MySQL service in the list and stop it.

If your server is not running as a service, you may need to use the Task Manager to force it to stop.

Читайте также:  Ethernet неопознанная сеть windows 10 как исправить

Create a text file containing the password-assignment statement on a single line. Replace the password with the password that you want to use.

Save the file. This example assumes that you name the file C:\mysql-init.txt .

Open a console window to get to the command prompt: From the Start menu, select Run , then enter cmd as the command to be run.

Start the MySQL server with the init_file system variable set to name the file (notice that the backslash in the option value is doubled):

If you installed MySQL to a different location, adjust the cd command accordingly.

The server executes the contents of the file named by the init_file system variable at startup, changing the ‘root’@’localhost’ account password.

To have server output to appear in the console window rather than in a log file, add the —console option to the mysqld command.

If you installed MySQL using the MySQL Installation Wizard, you may need to specify a —defaults-file option. For example:

The appropriate —defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel , then Administrative Tools , then Services . Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the —defaults-file setting.

After the server has started successfully, delete C:\mysql-init.txt .

You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server and restart it normally. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.

If the ALTER USER statement fails to reset the password, try repeating the procedure using the following statements to modify the user table directly:

How to reset the root password in MySQL 8.0.11?

I have actually lost my root password and I need to change it. I follow these steps :

Step # 1: Stop the MySQL server process.

Step # 2: Start the MySQL (mysqld) server/daemon process with the —skip-grant-tables option so that it will not prompt for a password.

Step # 3: Connect to the MySQL server as the root user.

First error, so I tried :

Always the same error said :

How can I resolve this?

6 Answers 6

This function was removed in MySQL 8.0.11

1.if you in skip-grant-tables mode
in mysqld_safe:

and then, in terminal:

2.not in skip-grant-tables mode
just in mysql:

Jus login to mysql with sudo

Step 1: Create a new file in your root directory( e.g C:) Step 2: Write this ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘abc’ and save it Step 3: If your Mysql service is already running, please stop this and open your CMD Step 4: Go to your Mysql installation directory (e.g C:\Program Files\MySQL\MySQL Server 8.0\bin) and type this command

Step 5: Execute this command and you are good to go 🙂

I am using 8.0.23 but had multiple issues. Here are the issues and solutions. I followed the mysql docs and was able to do the reset, though I had isues. I have provided my solutions and a sample reset script.

  1. following steps outlined by others had various failures
  2. user running daemon is mysql and I cannot su to mysql id
  3. getting error can’t create lock file /var/run/mysqld/mysqlx.sock.lock , mysqld folder is getting deleted by the mysql service.
  4. had to kill -9 mysql process after running, very ugly
  1. use steps from https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
  2. use —user=mysql when running mysql commands
  3. Create folder /var/run/mysqld and chown for mysql:mysql before runing comamnds
  4. use mysqladmin shutdown to stop sql after starting it for reset

In the script, I will reset root to New%Password

Оцените статью