SQL Access Denied - mysql

I'm working through tutorials in the book 'Cloning internet apps w/ Ruby.' I've made web apps before but they depended on sqlite and now I have to use mysql.
I've installed community server but when I try to create a database using the command line I'm receiving the error message listed above.
$ mysql
mysql> create database tinyclone;
Returns
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'p'
Notes:
The mysql command-line client flashes open and immediately closes, so I'm accessing it from the command prompt.
I've installed and uninstalled mysql several times in attempts to figure out this problem. In the latest install, I didn't set a password.
I'm aware that this line should probably be '$mysql -u <username> -p <password>' but I didn't set a password and I'm not sure what the username would be.

By default, the user is root
If you havn't set a password, use $ mysql -u root

The default MySQL username is 'root', try that without a password

The default username for MySQL is root, so you can try by
$ mysql -u root
by default it logs you with your Linux account. If you're logged as root on your Linux machine it will be OK just using $ mysql

Related

Unable to connect to MySQL instance after installing

I'm setting up a MySQL database following this tutorial. I installed it and successfully initialized an instance with a root password, but I am having trouble connecting to the instance via command line. When I click on the 'mysql' executable under bin, I get this message
ERROR 1045 (28000): Access denied for user 'hunter'#'localhost' (using password: NO)
and if I try to enter
> mysql -u root -p
in the terminal I get this message
-bash: mysql: Permission denied
It says in the instructions that I should be getting prompted to enter the password for the database, but for some reason it won't let me.
I would suggest first off to try a mysql workbench. You can download it at https://dev.mysql.com/downloads/workbench/ .
It seems that calling mysql from bash is causing issues for you. If you are using a *Nix environment, it could be a permissions issue and you need to set the correct permissions on the mysql binary. However, usually a correct installation should have already done that. See: https://askubuntu.com/questions/229589/how-to-make-a-file-e-g-a-sh-script-executable-so-it-can-be-run-from-a-termi
Secondly, you should use the username root . hunter is not default username.
From the mysql documentation:
How to Reset the Root Password
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”.
Reference:
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

Problems with mysql on linux and also importing a dump from windows

I'm a beginner with linux (linux mint distro) and I have been trying to install mysql server and workbench. I couldn't connect to mysql server without sudo command. I tried to connect to the server on workbench, and Access denied for user 'root'#'localhost'. So I try to run workbench with sudo from terminal. Nothing. So I followed what somebody posted here on stackoverflow about changing my password auth mode to mysql_native_password, and was able to access SQL Server from workbench (only using sudo command).
So I try to import a dump which I made on windows mysql-workbench, and it gives me two errors:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
and
ERROR 1115 (42000) at line 24: Unknown character set: 'utf8_general_ci'
Nevertheless, the database seems to have been correctly imported (I can see values and columns and tables and they look alright).
What's happening and how to stop getting these access denied errors? I tried to search the web and there are different answers, but none of them seem to address first install. I don't see why wouldn't it work if I have made a pretty default install :(
Thanks a lot!
ps: I don't know if more specific info is needed. anonymous user was dropped after installation
Try resetting root password.
Step 1. Access to mysql using mysql -uroot
Step 2. Check the root user
select Host, User, authentication_string from mysql.user;
Step 3. Change password for root user
use mysql;
update user set authentication_string=password('NEWPASSWORD') where user='root';
flush privileges;
​quit;
Now try accessing to mysql using mysql -uroot -p using new password. If it works, use the credentials in workbench.

Xampp access denied error

I am facing this error every time I create a database in CLI interface of mysql:
I am using Xampp
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
more reference Reference
A simple and 100% working solution for this problem is:
Install Xampp outside the C: Folder and it will definitely work for you, without any permission problems ever.
But remember to provide xampp-control.exe administrative privileges always to terminate any port problems.

Unable to access MySQL after it automatically generated a temporary password

I have erased and installed OSX 10.11 El Capitan and I have been following through this tutorial to get MySQL up and running on the new OS X. The first step was to download MySQL For Mac OS X 10.9 (x86, 64-bit), DMG Archive (works on 10.11, they recommended in the tutorial). While I were finishing installing the MySQL, I got the message saying that :
2015-10-25T02:10:54.549219Z 1 [Note] A temporary password is generated for root#localhost: R>gFySuiu23U
If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.
That was weird, I have never seen that kind of message. After that, I started MySQL via the Preference Pane and then use /usr/local/mysql/bin/mysql -v command on the terminal for another step. I got an error message saying that :
ERROR 1045 (28000): Access denied for user 'cheetah'#'localhost' (using password: NO)
I have also tried to access database through Sequel Pro using root as username and blank password, I got access denied message saying that :
Unable to connect to host 127.0.0.1 because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
MySQL said: Access denied for user 'root'#'localhost' (using password: NO)
Okay, I also tried this again using root as a username but 'R>gFySuiu23U' as a password (which was generated from MySQL). I got connection failed message saying that :
Unable to connect to host 127.0.0.1, or the request timed out.
Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).
MySQL said: Your password has expired. To log in you must change it using a client that supports expired passwords.
How could I solve this problem? I remember that MySQL has never got automatically generated a temporary password like this, hasn't it ?
Try this:
mysql -u root -h 127.0.0.1 -p
Enter password: (enter the random password here)
Ref:https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html
Following this, you may reset your password using
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new-password';
This is what worked for me on OS X Yosemite running MySql v5.7 (installed from the .dmg).
cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password
(Enter the temporary password generated by the installer.)
This gets you into sandbox mode and mysql> prompt. Then set desired root password with SET PASSWORD:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('mySuperSecretPassword');
Now that the password MySQL had generated is expired, the problem is reduced to getting this password to work again (1) or generate a new one (2). This can be accomplished by running MySQL with the skip-grant-tables option which would make it ignore the access rights:
Stop your MySQL server.
Add the below at the end of the [mysqld] section of my.cnf file and save it.
skip-grant-tables
Start MySQL server.
In terminal, type
mysql -u root -p
to get into MySQL command prompt.
In the command prompt, type
USE mysql;
to get into the mysql database where it keeps database users.
Type
UPDATE user SET password_expired = 'N' WHERE User = 'root';
to let MySQL know the password is not expired (1) or
UPDATE user SET authentication_string = PASSWORD('YourNewPassword'), password_expired = 'N' WHERE User = 'root';
to assign a new password YourNewPassword to root (2).
Doing these steps under OSX 10.11 El Capitan and MySQL 5.7.X, should do the trick.
Considering that you already have MySQL installed then..
Open a terminal window and type:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
Since the command fired in the step 2 will be under on going state, you need to open another terminal window and then type:
mysql -u root -p
UPDATE mysql.user SET password_expired='N', authentication_string=PASSWORD('') WHERE User='root';
quit;
sudo /usr/local/mysql/support-files/mysql.server restart
Important: in the step 2 you must replace for your password.
Hope it will wok for you.
MySQL password expired
Resetting the password will solve the problem temporarily, however, from MySQL 5.7.4 to 5.7.10 (I think to encourage better security) the default value for the default_password_lifetime variable is 360 (about a year). For those versions, if you make no changes to this variable (or to individual user accounts) all user passwords expire after 360 days.
Typically, from a script you might get the message: "Your password has expired. To log in you must change it using a client that supports expired passwords."
So, to prevent automatic password expiry, log in as root (mysql -u root -p), then, for clients that automatically connect to the server (e.g. scripts.) change the password expiration settings for those clients:
ALTER USER 'script'#'localhost' PASSWORD EXPIRE NEVER;
or you can disable automatic password expiration for all users:
SET GLOBAL default_password_lifetime = 0;
Links:
MySQL: Password Expiration and Sandbox Mode
MySQL: Password Expiration Policy
Password expiration policy in MySQL Server 5.7
I'm running macOS Sierra(10.12.3) and I installed mysql-5.7.17-macos10.12-x86_64.dmg.
The answer from #lesley worked for me with the exception that I needed to add ./ to ensure I was calling the mysql binary in my current working directory. Which is where the aforementioned package was installed.
If you cd to /usr/local/mysql/bin and run mysql -u root -p --connect-expired-password, you could receive the following error.
mysql: unknown option '--connect-expired-password'
I did. Because simply running mysql without providing a path, called a previously installed version of the MariaDB client.
So to ensure you are executing the correct binary, you can either
provide the absolute path
/usr/local/mysql/bin/mysql -u root -p --connect-expired-password
or the relative path after changing directories
cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password
Both ways should work. Once you are connected to the client, the instruction are the same as above from #lesley.
Enter your temporary password generated by the installer and set your new password.
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('yourNewPassword');
I faced the same problem. I followed the installation process guide from https://www.ntu.edu.sg/home/ehchua/programming/sql/MySQL_HowTo.html and downloaded DMG archive and installed MySQL on my MAC OS X 10.12.2.
Finally executed the following commands on new Terminal.
cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password
It worked.
Answer 7 worked for me: El capitan, MySQL installed from dmg and autogenerated password, but made sure to cd to /usr/local/bin/mysql before entering ./mysql -root -p Obvious, but I didn't the first time.
Now to find where all my databases and tables are and how to link them in.
For Mysql 5.7 I use
shell $ > sudo grep 'temporary password' /var/log/mysqld.log
This particular one did the trick for me:
As specified in this link: https://www.variphy.com/kb/mac-os-x-reset-mysql-root-password
Do all the steps except executing
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
Execute
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
And then execute
FLUSH PRIVILEGES;
The another way to solve this issue is to use an older version of MySQL instead.
I have uninstalled MySQL version 5.7.9 for Mac OS X 10.9 (x86, 64-bit), DMG Archive and then install the older version, MySQL version 5.6.7 for Mac OS X 10.9 (x86, 64-bit), DMG Archive. This issue is solved. The given autogenerated password before finishing installation of this older version is gone and I can ultimately access the database using root as username and a blank password. Everything is working like a charm!
I installed view brew, and I had the same error message until I noticed this caveat:
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
I got around this problem by running
'mysql -u root -p --connect-expired-password'
Then input the expired auto-gen password from mysql. Finally got in. Selected mysql db with
'use mysql'
and then updated user 'root' pw with
'ALTER USER 'root'#'localhost' IDENTIFIED BY 'your new password'
Installing MySQL manually by downloading packages for the first time generates a default password for root. Copy and save that. If not done somehow on successive re-installations it does not show that password.
Thus you cannot login to root.
Do the following :
Find mysql related entries from system
sudo find / -name mysql
Remove all mysql related entries by doing rm -rf <mysql_entries_above>
Download latest mysql-server and intall it.
You will be promted with a default password which you need to copy.
Run mysql_secure_installation and paste that password when asked for root.
Subsequently follow the steps and change admin password when prompted for.
Restarting Mysql server worked for me.
But in Mysql80-Server, it is more complicated than 5.7. In MySQL80 not allow you to update or change password during the config in my.cnf in state "skip grant table". So you need 3 big steps to do
I) change my.cnf to skip-grant-table
II) login MySQL with blank password & update table to blank password
III) restart mysql and login with blank password and update to new password
Step to do: (whatever, you forgot root password, temporary password gen by installation not work, etc. please follow the steps below) In my case on FreeBSD 12.2
stop your mysql server by
/usr/local/etc/rc.d/mysql-server stop
recheck again whether it is really stop (in case more serious problem than that)
/usr/local/etc/rc.d/mysql-server status
mysql is not running.
find your my.cnf file and add "skip-grant-tables" to it.
(normally before [Mysqldump] head)
restart mysql
/usr/local/etc/rc.d/mysql-server start
login to mysql
mysql -u root -p
when it ask for password, just press enter and you will log into mysql
select DB to use
use mysql
look at the table user
select user, authentication_string,password_expired from user;
update to blank password
UPDATE user SET authentication_string = '', password_expired='N' WHERE User = 'root';
quit mysql and make mysql stop
goto file my.cnf then take "skip-grant-tables" out of file.
restart mysql again with "mysql -u root -p" enter the blank password
then
ALTER USER 'root'#'localhost' IDENTIFIED WITH
caching_sha2_password BY 'YourNewPassword';
quit mysql and make mysql stop
restart mysql again then you will login with your new password
This may happens when you have installed mysql before.
Try the password you set for the last version of mysql.
This did work for me.

I can't set the root password for MySQL

I've just set up a LAMP server using SuSE Server 10. I want to set the root password for MySQL, so I entered the following in the terminal:
mysqladmin -u root password MyPassword
and the output is:
mysqladmin: Can't turn off logging; error: 'Access denied; you need SUPER
privilege for this operation'
I'm not really certain what SUPER privilege is for mysqladmin, and all my Google searches have been fruitless. I am able to use mysql from the command line without entering a password like this:
mysql -u root
But I can't access the mysql database to update the root password that way. Here is the output:
mysql> USE mysql;
mysql> ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'mysql'
Any help would be greatly appreciated. Thanks.
I am still unsure what the solution to this problem is, but the solution I came up with was to install SuSE 11. Everything is working now. I think there was just a problem with my initial install.