Mysql version - mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper.
I had forgotten my password and tried many commands online.Also the problem is that grant tables command not working in my terminal.
~$ cat /etc/issue
Ubuntu 16.04.3 LTS \n \l
~$ aptitude show mysql-server |grep Version
Version: 5.7.20-0ubuntu0.16.04.1
In file: /etc/mysql/debian.cnf are two important lines:
user = debian-sys-maint
password = <unique password>
Use that user and password to login to mysql:
Once logged in as debian-sys-maint you can:
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password';
The following adjustments works for my setup:
$ sudo mkdir /var/run/mysqld
$ sudo chown mysql: /var/run/mysqld
$ sudo kill -9 $(sudo cat /var/run/mysqld/mysqld.pid)
1) Stop the Database Server.
sudo systemctl stop mysql
2) Restarting the Database Server Without Permission Checking. For this following command
sudo mysqld_safe --skip-grant-tables --skip-networking &
3) Connect to the database as the root user
mysql -u root
4) Change the Root Password
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password';
5) Restart the database server narmally
sudo kill `cat /var/run/mysqld/mysqld.pid`
sudo systemctl start mysql
Now login with new password in database:
mysql -u root -p
Or you can follow the following link:
https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password
I had tried all the approaches but didn't work for me. The following approach worked. I am hopeful that it will work on different versions of ubuntu.
OS info:
mysql --version
mysql Ver 8.0.28-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
First, stop MySQL service using command
sudo systemctl stop mysql
Other commands didn't work and here how I start the MySQL server without any permission-checking. To do so, run:
// open the mysql systemd configuration file your default text editor.
// In my case, it is nano editor.
sudo systemctl edit mysql
// Add the following 3 lines
[Service]
ExecStart=
ExecStart=/usr/sbin/mysqld --skip-grant-tables --skip-networking
Reload systemd configuration using command:
sudo systemctl daemon-reload
Start MySQL service
sudo systemctl start mysql
Now, connect to MySQL server as root user without password:
sudo mysql -u root
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH caching_sha2_password BY 'add-newpassword-here';
Revert the modified systemd configuration
sudo systemctl revert mysql
You are all Done.
Related
I am giving this script as a userdata in an ec2 instance to install and setup mysql. The code runs fine manually but when given to ec2 instance as userdata it doesnot creates the database or user.
#!/bin/bash
sudo yum -y update
sudo yum -y install aspell aspell-en httpd24 mysql mysql-server php56 php56-cli php56-gd php56-intl php56-mbstring php56-mysqlnd php56-opcache php56-pdo php56-soap php56-xml php56-xmlrpc php56-pspell --skip-broken
sudo yum list installed
sudo /sbin/chkconfig httpd on
sudo /sbin/chkconfig mysqld on
sudo /sbin/service httpd start
sudo /sbin/service mysqld start
sudo mysqladmin -u root password '123a'
sudo mysql -u root -p123a
CREATE DATABASE db;
CREATE USER '1234'#'localhost' IDENTIFIED BY '123a';
GRANT FILE ON *.* TO '1234'#'localhost';
FLUSH PRIVILEGES;
Mysql version: 5.7.28
Your grant command is not right, nowadays it is simply without password
sudo mysql -u root -p123a -e "CREATE DATABASE db DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;use db;create user 'db'#'localhost' identified by '123a'; grant all on testdb.* to 'db';GRANT ALL ON db.* TO ' db '#'localhost';GRANT ALL ON db.* TO ' db '#'%';FLUSH PRIVILEGES;"
I'm re-installing MySQL (5.7.29) for Ubuntu Linux 18.04 LTS. I installed the package using apt & started the service without issue. I was not asked for a root password during the install and am not able to login.
I assume (from dev.mysql.com/doc/refman/5.7/en/default-privileges.html) that the data directory was initialized without my knowledge.
I used $tail /var/log/mysql/error.log -n 50 to see if an initial random pwd was created - no luck.
I also tried $mysql -u root --skip-password, which also fails due to access denial.
It's been a couple of years since I've used MySQL. What am I doing wrong? TY!
Ubuntu let the user login with the root account, this beahavior is default on MariaDB installations too:
sudo su -
mysql
If this don't resolve, you can start mysql without the tables associated with authentication:
sudo su -
systemctl stop mysql
mysqld --user mysql --skip-grant-tables &
mysql -h 127.0.0.1 --protocol tcp mysql -e "ALTER USER root#localhost IDENTIFIED BY 'mypassword'"
mysql -h 127.0.0.1 --protocol tcp -e 'shutdown'
systemctl start mysql
And try again ;)
I forgot my Mysql Root password.I have uninstalled Mysql using the following commands-
sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
After uninstalling MySQL I ran the following command to verify if MySQL was uninstalled properly-
dpkg --get-selections | grep mysql
Then I executed the following command to install MySQL-
sudo apt-get install mysql-server
I didn't get any message to set root password.
After Executing the following command it ask's for root password which i haven't set.
mysql -u root -p
Please help.
Stop the MySQL server process with the command service mysql stop
Start the MySQL server with the command mysqld_safe —skip-grant-tables —skip-networking
Connect to the MySQL server as the root user with the command mysql -u root
Exec the following MySQL commands to reset the root password:
mysql> use mysql;
mysql> update user set authentication_string=password('NEWPASSWORD') where user='root';
mysql> flush privileges;
mysql> quit
Where NEWPASSWORD is the new password to be used.
Restart the MySQL daemon with the command service mysql restart. You should now be able to log into MySQL with the new password.
How can I get mysql installed and able to use it?
I've tried:
$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.9.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/mysql-5.7.9.yosemite.bottle.tar.gz
==> Pouring mysql-5.7.9.yosemite.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To connect:
mysql -uroot
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql/5.7.9: 12629 files, 464M
$ mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
$ mysql.server start
Starting MySQL
SUCCESS!
$ mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
$
For me turns out i already had mysql somewhere on my computer so a password was set there or something. After spending hours trying every solution out there this is what worked for me:
$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot
all credit to #Ghrua
I just had the same problem, this is how i solved it (but only try this if you have no data in your db!!):
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm -rf /usr/local/var/mysql
mysqld --initialize
The initialize method will create the data dir, and also an root user with a temporary password, be sure you copy this password, and than login and change the password.
Try in CLI :
mysql -uroot -p
You need to specify that this user has a password.
Using mysqld --initialize worked for me. I just had to cut-n-paste the password from the below output.
[Note] A temporary password is generated for root#localhost: ?(A+3F48ed.Y
Try to use this commande:
sudo mysql -u root -p
then Enter password:*******
I have installed Mysql Ver 14.14 Distrib 5.7.9, for Linux (x86_64) using EditLine wrapper On CentOS Linux release 7.1.1503
I Changed root password using this command:
alter user 'root'#'localhost' identified by 'XXXXXXX';
flush privileges;
After re-login
[root#server ~]# mysql -u root -p
Enter password:
ERROR 1524 (HY000): Plugin
'*A6074285732753D325C55AD74E7517CF442C1A81' is not loaded
Two things have changed since earlier versions of mySQL (I''m using 5.7.10):
systemd is now used to look after mySQL instead of mysqld_safe (which is why I was getting the -bash: mysqld_safe: command not found error - it's not installed)
The user table structure has changed.
So to reset the root password, you still start mySQL with --skip-grant-tables options and update the user table, but how you do it has changed.
1. Stop mysql:
systemctl stop mysqld
2. Set the mySQL environment option
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
3. Start mysql usig the options you just set
systemctl start mysqld
4. Login as root
mysql -u root
5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
-> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit
6. Stop mysql
systemctl stop mysqld
7. Unset the mySQL envitroment option so it starts normally next time
systemctl unset-environment MYSQLD_OPTS
8. Start mysql normally:
systemctl start mysqld
Try to login using your new password:
7. mysql -u root -p
Reference
As it says at http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html,
Note
As of MySQL 5.7.6, for MySQL installation using an RPM
distribution, server startup and shutdown is managed by systemd on
several Linux platforms. On these platforms, mysqld_safe is no longer
installed because it is unnecessary. For more information, see Section
2.5.10, “Managing MySQL Server with systemd”.
Which takes you to http://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html where it mentions the systemctl set-environment MYSQLD_OPTS= towards the bottom of the page.
The password reset commands are at the bottom of http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
You should use update on mysql user table when changing any user, especially root.
You should follow these steps to reset it:
How to reset the root password for mysql:
Stop mysql:
1. service mysql stop
Run mysql with skip grants to be able to login without any password
2. mysqld_safe --skip-grant-tables &
Login as root
3. mysql -u root
4. mysql commands:
mysql> use mysql;
mysql> update user set password=PASSWORD("YourPWHere") where User='root';
mysql> flush privileges;
mysql> quit
Stop mysql
5. service mysql stop
Start mysql normally:
6. service mysql start
Try to login using your new password:
7. mysql -u root -p
Update:
Apparently this method will not work for 5.7, please refer to Here and Here instead.
Use the below Steps to reset the password.
$ sudo systemctl start mysqld
Reset the MySql server root password.
$sudo grep 'temporary password' /var/log/mysqld.log
Output Something like-:
10.744785Z 1 [Note] A temporary password is generated for root#localhost: o!5y,oJGALQa
Use the above password during reset mysql_secure_installation process.
$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
You have successfully reset the root password of MySql Server.
Use the below command to check the mysql server connecting or not.
$ mysql -u root -p
See my article: Install Latest MySQL 5.7 on RHEL/Centos 7