MySQL general SET-UP - mysql

I am new to MySQL, and I got some general problems and thanks for any help:
My OS is MAC SnowLeopard, and when I type 'mysql' in terminal, I could successfully go into the mysql system, but, I have no rights to create databases:
mysql> create database A;
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'a'
I tried command line 'mysql -u root', I got the following:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I was thinking that I may set up the username for the database, which made me not possible enter mysql using root as username?
Then I tried 'localhost' as username, which I guess or remember I set it or not, using the command 'mysql -u localhost', I could successfully logged in to mysql, but STILL, cannot create database,
mysql> create database a;
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'a'
I am not sure:
why root not working;
weather I set up the username and password myself before...sorry...really have no memory now.
If I have set up the username as 'localhost' before, I cannot remember the password, therefore I have no rights to create database?
What should I do to recover the password, in the case of no root access?
If not possible, how to uninstall it? The PATH in .bash_profile for mysql is /usr/local/mysql/bin
I got a check: sudo port list installed | grep mysql
mysql5 #5.1.65 databases/mysql5
mysql5 #5.1.65 databases/mysql5
py26-mysql #1.2.3 python/py-mysql
does the mysql in /usr/local/mysql/bin refer to this one listed here?
Edit
The result of running ps -ef | grep mysql:
0 107 1 0 0:00.01 ?? 0:00.02 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/XXX-MacBook-Pro.local.pid
74 245 107 0 0:03.51 ?? 0:18.35 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/mysql/plugin --user=mysql --log-error=/usr/local/mysql/data/XXX-MacBook-Pro.local.err --pid-file=/usr/local/mysql/data/XXX-MacBook-Pro.local.pid
501 3790 417 0 0:00.00 ttys000 0:00.00 grep mysql
501 3337 1271 0 0:00.00 ttys001 0:00.01 mysql -u localhost

You'll need to reset your root password. To do this, follow those simple steps:
Stop MySQL: sudo port unload mysql5-server
Start MySQL using /opt/local/lib/mysql5/bin/mysqld_safe --skip-grant-tables &
Connect to MySQL: mysql -uroot
Reset your MySQL password:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Stop MySQL again sudo killall -9 mysqld_safe
Restart MySQL normally sudo port load mysql5-server
Connect to MySQL: mysql -uroot -p
EDIT
Added commands to stop/start MySQL.

Related

Error even after starting mysql server with --skip-grant-tables

I have forgotten the password for mysql server. Even after starting the server with --skip-grant-tables I get the below error.
ER
ROR 1045 (28000): Access denied for user 'ODBC'#'localhost' (using
password: NO)
This is for windows.
Also I get the error even for mysql -u root
What could be the issue?
Here is what you need to do
First ensure that mysqld is not running.
ps aux | grep mysqld
if it is running. Stop it. Then,
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
FLUSH PRIVILEGES;
SET PASSWORD FOR root#'localhost' = PASSWORD('password');

How to recover mysql root password in MacOS

I start my MAMP and try to connect to my MySQL server via localhost or 127.0.0.1, I tried all the possible password that I think it is correct, but for some reasons it still didn't like it, so I think I forgot it somehow. I need help.
Try #1
Enter all the possible passwords
MySQL -u root -h localhost -p
Enter password: <---I've tried almost 10 possible passwords
I got
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Try #2
Enter possible passwords
MySQL -u root -h localhost
I got
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Try #3
MySQL.server stop
I got
ERROR! MySQL server PID file could not be found!
I'm trying to run this
mysqld_safe --skip-grant-tables &
I got
Try #4
mysqld_safe --skip-grant-tables &
I got
[1] 72194
🌈 ~ 2017-10-04T12:13:42.6NZ mysqld_safe Logging to '/usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.err'.
2017-10-04T12:13:42.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2017-10-04T12:13:44.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.pid ended
Open a new tab
MySQL -u root
I still get
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Try #5
Close my MAMP application, and run this
mysqld_safe --skip-grant-tables &
I got
[1] 72194
🌈 ~ 2017-10-04T12:13:42.6NZ mysqld_safe Logging to '/usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.err'.
2017-10-04T12:13:42.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2017-10-04T12:13:44.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/BH-MacBook-Pro-15-512GB.local.pid ended
Open a new tab
MySQL -u root
I still get
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I don't what else to try anymore.
I can't really set the root password because I can't even get in.
This is the process of my MySQL
ps aux | grep MySQL
bheng 95850 0.2 1.0 2869440 175404 ?? S 8:48AM 0:00.28 /usr/local/opt/mysql/bin/mysqld --basedir=/usr/local/opt/mysql --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mysql/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/bh-mbp-15-512gb.ad.benu.net.err --pid-file=/usr/local/var/mysql/bh-mbp-15-512gb.ad.benu.net.pid
_mysql 124 0.0 0.0 2864848 4040 ?? Ss 22Sep17 0:32.26 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so
bheng 95863 0.0 0.0 2423384 396 s009 R+ 8:48AM 0:00.00 grep mysql
bheng 95749 0.0 0.0 2448756 2496 ?? S 8:48AM 0:00.03 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --bind-address=127.0.0.1 --datadir=/usr/local/var/mysql
bheng 66379 0.0 0.1 2696936 9304 ?? S 8:06AM 0:00.51 /Applications/MAMP/Library/bin/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql --plugin-dir=/Applications/MAMP/Library/lib/plugin --log-error=/Applications/MAMP/logs/mysql_error_log.err --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --socket=/Applications/MAMP/tmpmysql/mysql.sock --port=8889
bheng 66263 0.0 0.0 2446708 2100 ?? S 8:06AM 0:00.02 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log
🌈 ~
This is how you can do it in macOS Sierra, probably you install it via pkg and in the system preferences have an icon for MySQL, something like this:
If is up and running open a terminal and run this command:
pgrep -fl mysql
That will help you to find the path of mysqld and the current command used to start the server, the output could be something like this:
6283 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
Next step is to stop MySQL, you can do this by clicking on the System Preferences menu and click on the Stop MySQL Server button, Once is stoped within a terminal you will need to start again the server but with some extra options, something like this:
sudo /usr/local/mysql/bin/mysqld \
--skip-grant-tables \
--skip-networking \
--user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
It is indeed the same command from the output of pgrep -fl mysql but in this case, you just need to add:
--skip-grant-tables --skip-networking
After doing that you will notice that the menu from the System Preferences is Green again and MySQL should be up and running, now you can try to login and change password:
mysql -uroot
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR root#'localhost' = PASSWORD('secret');
mysql> FLUSH PRIVILEGES;
mysql> exit
Stop and start again MySQL from the System Preference panel and it should be working now with the new password.
Please follow the steps in same sequence.
Make sure, your MySQL server is down. Execute below command :
mysql.server stop
Then, start MySQL server in safe mode
mysql.server start --skip-grant-tables --skip-networking
Then, connect to MySQL using root user.
mysql -u root
Change the database from none to mysql
MariaDB [(none)]> use mysql;
Database changed
Update both authentication_string and password column with same password as shown below (if you get column not found error then remove one )
MariaDB [mysql]> update user set authentication_string=PASSWORD('password'), password=PASSWORD('password') where user='root';
MariaDB [mysql]> FLUSH PRIVILEGES;
MariaDB [mysql]> quit;
Now, stop everything including MySQL server and MAMP application as well.
And, search for config.inc.php file inside your MAMP folder (you could use command + space and search this file).
You may not have privilege to change this file. After updating the privilege of the file you need to look for $cfg['Servers'][$i]['password'] and update the password value as shown below.
$cfg['Servers'][$i]['password'] = 'password';
Save this file and restart everything in normal mode. And try connecting root user with new password as shown below :
mysql -uroot -ppassword
You have to reset the MySQL root password as follow :
/etc/init.d/mysql stop
/usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR root#'localhost' = PASSWORD('new_password');
mysql> FLUSH PRIVILEGES;
mysql> exit;
service mysql restart
And then, you will be able to connect using :
mysql -u root -p
Your password
Follow those instructions and you should be fine:
https://svendeswan.wordpress.com/2016/01/26/mysql-reset-root-password-without-knowing-it-mac-mamp/
which is based on this one:
https://www.tech-otaku.com/local-server/resetting-mamp-mysql-root-user-password/

Cannot Set Root Password MySQL CentOS 6

Overview
Hi! I'm new to Linux, but I was able to get MySQL installed and running on several VPS; however, I recently reset my VPS by reinstalling CentOS 6. I've run into a problem regarding MySQL where it won't let me log in or set a password. I've never run into this issue before, so I'm hoping for someone to see if they can help me out.
Steps that replicated the issue
yum install wget
wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
sudo yum localinstall mysql57-community-release-el6-8.noarch.rpm
yum install mysql mysql-server
/etc/init.d/mysqld start
mysqladmin -u root -p "setpasswordhere"
At the last step it won't let me and tells me to input the current root password, but I was never prompted to set a password in the first case. I've reinstalled the VPS 2-3 times now and done the same procedure that didn't cause me the problems in the past. Albeit reinstalling the entire VPS isn't the greatest thing to do, but in times where I'm completely lost and new to something, reinstalling and starting from scratch only takes about 5-10 minutes.
Research:
I followed some steps for installing MySQL here: https://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html
The error message is:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
Or
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: YES)'
So obviously a password is set here, but I'm never prompted to create one in the first place.
Console Output:
[root#vps83299 ~]# mysqladmin -u root -p ""
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
[root#vps83299 ~]#
Error when I get when following this instruction: https://ubuntu.flowconsult.at/en/mysql-set-change-reset-root-password/
mysql> update user set password=PASSWORD("newpass") where User='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
For acess mysql, use:
mysqladmin -uroot -psetpasswordhere
or
mysql -uroot -psetpasswordhere
RECOVER MYSQL ROOT PASSWORD( for linux users)
#
Login to root user and run step1 and 2
Step 1# /etc/init.d/mysql stop
Step 2# mysqld_safe --skip-grant-tables &
Output : Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: startedStep # 3: Connect to mysql server using mysql client:
Keep this running................
Step 3
Login to new terminal (with root user)
mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD('NEW-ROOT-PASSWORD') where User='root';
mysql> flush privileges;
mysql> quit
Step 4 # Stop MySQL Server:
/etc/init.d/mysql stop
Step 5 # /etc/init.d/mysql start
mysql -u root -pNEWPASSWORD
--------------------- completed----------

Reset admin password for MySQL and Plesk on CentOS 6

I have updated mysql using...
wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
yum localinstall mysql57-community-release-el6-7.noarch.rpm
yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql55-community
yum update mysql-server
Everything went fine. But then when I tried to update the tables etc with
mysql_upgrade -u root -p
I got
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Error: Failed while fetching Server version! Could be due to unauthorized access.
FATAL ERROR: Upgrade failed
I tried
mysql_upgrade -uadmin -p
and
mysql_upgrade -uadmin -p`cat /etc/psa/.psa.shadow`
after reading that this was what was needed for Plesk, but it had the same result.
mysqlcheck --all-databases --check-upgrade --auto-repair
gave
mysqlcheck: Got error: 1045: Access denied for user 'root'#'localhost' (using password: NO) when trying to connect
At this point I checked passwords but I thought they were correct.
At this point I messed up when trying to change/update/reset the password in mysql. I followed code I found online...
cp /etc/psa/.psa.shadow /etc/psa/.psa.shadow.bak # just backup
chmod 400 /etc/psa/.psa.shadow.bak # just secure backup
echo "PLACE PLAIN PASSWORD OF MySQL user ADMIN HERE" > /etc/psa/.psa.shadow
and also
mysql -uadmin -p'cat /etc/psa/.psa.shadow' mysql -e "update user set Password=password('password') where User='admin'; flush privileges;"
And now I have
Unable to connect to database: mysql_connect(): Access denied for user 'admin'#'localhost' (using password: NO) (Error code: 1045) (Abstract.php:69)
when trying to connect to Plesk.
So I think now my mysql admin password and password in /etc/psa/.psa.shadow do not match? I have been trying to find how to start again by setting a mysql admin password and the same for /etc/psa/.psa.shadow, but at this point I decided to ask for help!
Is there anybody who can help me? :)
So I think now my mysql admin password and password in /etc/psa/.psa.shadow do not match?
Yes, you are right.
You can just set password for MySQL's admin user back from /etc/psa/.psa.shadow like:
mysql -uadmin -pYouCurrentPassword -e "update user set Password=password('string from .psa.shadow') where User='admin'; flush privileges;"
After this it's should be possible to login to plesk and change password to new one if you need.

access denied mysql monitor

I installed xampp on 10.9 mavericks. Unfortunately the command mysql does not work in the terminal. I managed to start the mysql monitor from xamppfiles/bin/. When I try to create a new database I get
ERROR 1044 (42000): Access denied for user ''#'localhost' to database XY
What can I do?
No, you should run mysql -u root -p in bash, not at the MySQL command-line. If you are in mysql, you can exit by typing exit.
You may need to set up a root account for your MySQL database:
In the terminal type:
mysqladmin -u root password 'root password goes here'
And then to invoke the MySQL client:
mysql -h localhost -u root -p