In your case, I'd try /usr/local/mysql/bin/mysql -u root -p then hit enter. Mysql will prompt you for your password - type in in and hit enter again. If it's wrong mysql will let you know and then you'll have to go about resetting the mysql root password. Reset the MySQL root password Linux and Mac OS X. If you don’t remember your MySQL root password, you can follow the steps below to reset it to a new value: Create a file in /tmp/mysql-init with the content shown below (replace NEWPASSWORD with the password you wish to use). If your stack ships MySQL v8.x, use this content: ALTER USER 'root. Setting a root password for MySQL Start your command line by going to the Start Menu Run and typing cmd (or type command if you are using an older version of windows) Change directory to where you installed mysql to.
Author: Jeremy Druin Twitter: @webpwnized Thank you for watching. Up vote, subscribe or even support this channel at https://www.youtube.com/use. 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.
MySQL is an open-source relational database, made famous by its ease-of-use and simple setup on modern Linux and Windows operating systems. On an unmodified MySQL install, the root user account does not have a password. This is extremely insecure!
As a systems administrator, we know that the easiest way to compromise a system is using the default unchanged password with admin privileges. To set the root password for the root account:
{{code}} $ mysql -u root --skip-password {{/code}}
Assign a password with the following command:
{{code}} mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'PASSWORD_HERE'; {{/code}}
Luckily, in most situations, operating system-specific installs of MySQL will be set to generate a random password for the root user when the database is started for the first time. Instead of setting the password, you’ll change it.
Different platforms (Windows, Linux, etc) will require slightly different methods for resetting the password.
Changing the root user’s password on Linux
Log on to your system as the Unix user that the MySQL server runs as (for example, mysql). These will work on most Linux distributions (ubuntu, Debian, Fedora, etc).
- Log on to your target system with SSH or other remote shell
- Stop the MySQL server if it is running. Most times, this is done using your operating system’s init system (systemD, SysV init, or upstart).
{{code-block}}
# upstart
$ sudo service mysql stop
# SysV init
/etc/init.d/mysql-server stop
{{/code-block}}
- If you’re unsure, or you have a custom MySQL installation, you can stop the MySQL server by sending a normal TERM to the mysqld process using the kill command
{{code-block}}
$ killall mysqld
{{/code-block}}
- Create a text file containing the password assignment SQL statement on a single line
{{code-block}}
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
{{/code-block}}
- Save the file to disk. Note: ensure the mysql user (or the user the database is running under) has read access to the file.
- Start the MySQL server with the init_file CLI flag set to name the file you saved above.
{{code-block}}
$ mysqld --init-file=/home/me/mysql-init
{{/code-block}}
- When the server boots, it will execute the contents of the file specified above which will change the password.
- After the server has started successfully, you can delete the SQL file you created above. In a separate command prompt, or with your GUI tool of choice, you should now be able to connect to the MySQL server as root using the new password.
- Stop the MySQL server (usually control-C) and start MySQL it normally from your operating system’s init system
{{code-block}}
#upstart
$ sudo service mysql start
# SysV init
/etc/init.d/mysql-server stop
{{/code-block}}
Changing the root user’s password on Windows
Resetting the root password is very similar to the process used on Linux, with a few tweaks! We will create another init file containing the password reset statement, and start the server manually in our command prompt.
- Log on to your system via RDP or on the console as a user with administrative privleges
- 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.
- Create a text file containing the password assignment SQL statement on a single line
{{code-block}}
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
{{/code-block}}
- Save the file to disk.
- Open the command prompt (Start → Run → cmd)
- Start the MySQL server with the init_file CLI flag set to name the file you saved above. Note: backslashes must be escaped, so use two for the file path like the example below.
Root Password For Mysql
{{code-block}}
C:> cd 'C:Program FilesMySQLMySQL Server 8.0bin'
C:> mysqld --init-file=C:mysql-init.txt
{{/code-block}}
- When the server boots, it will execute the contents of the file specified above which will change the password.
- After the server has started successfully, you can delete the SQL file you created above. In a separate command prompt, or with your GUI tool of choice, 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 from the Windows Service Console.
Managing MySQL Users with strongDM
Most security professionals would not recommend using the root user for human or application access to a database. The administrative privileges that the root user possesses are a huge security vulnerability waiting to happen!
Mysql Change Root Password Sql
So what’s the best way to do database access for your developers? Multiple accounts? One shared account? If you change the password, how do you communicate that to everyone?
Enter strongDM. strongDM allows you to abstract-away usernames and passwords from the developers and allows us, the systems administrator, to keep the master passwords in a safe space under lock and key. strongDM provides us central authentication and auditing for all actions against a MySQL host.
shell > mysqladmin -u root old_password new_password
but I keep getting the error:
'Access denied for user: 'root@localhost' (Using password: NO)'
So I must not be typing something right.
The (old) password is working in other situations - PHPmyAdmin for example is connecting properly to MySQL.
I also tried installing the preference pane from the complete mysql installer, but I can't get it to activate. I installed MySQL directly from the MySQL site, so the version number is newer than the MySQL included with complete MySQL - probably the reason. Anyway, I should be able to change the password with the above command - right?
I'm running Mac OS X Panther (10.3.2), mysql 4.0.17
Thanks,
Bob
Comments are closed.