Trouble Restoring MYSQL Database on CentOS Using SSH - mysql

I just had to change [dedicated CentOs] servers at Godaddy.
After I uploaded my .sql database backup file to the site using FTP, I connected to my site using SSH.
After changing to super user using the su - command, i tried using the following code to restore my database:
[root#sXXX.XXX.XXX.XXX ~]# mysql -u alaskasl_destiny -p alaskasl_freakout < /home/alaskasl/backup/databases/alaskasl_freakout.sql
I get the following ERROR 1044 (42000): Access denied for user 'alaskasl_destiny'#'localhost' to database 'alaskasl_freakout'
I can't figure out what I am doing wrong. This command has always worked for me in the past

First and foremost, if alasas1... is your real username, I would replace it with 'username'. Never give that info out, especially on a public place like Stackoverflow.
That said, a few things to check
1. You need to know the root user's login credentials for this new mysql instance. If this is a new setup the user is root with no password, so you should be able to use the following command:
$ mysql -u root
Once you do get in to mysql, you will see a prompt similar to:
mysql>
at that prompt you can type
mysql> show databases;
and a list of databases will display. Does the database you expect to be in there in there?
if not, here is what you need to do:
mysql> CREATE DATABASE 'database_name';
mysql> CREATE USER 'username' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.database_name TO 'username';
mysql> exit
At this point what you did was create the database, create a user with a password in mysql, and granted access to that database for that user. Once you type exit, you should now be back at the command prompt.
Now you can run mysql -u username -p database_name < /path/to/sql_file.sql

Related

Why I cant create a new connection in SQL in VS code

When i am trying to make a new connection in VS Code, this error message popped-off
One another thing, Could someone just tell me what are the needed extensions to work with mysql in VS-code.
It's because mysql default root user cant login with password and is set to auth_socket. To change this behavior you should connect to mysql if you on linux with this command: sudo mysql -u root and run this command to enable password login: ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

ownCloud Setup: SQLSTATE[HY000][1045] Access denied for user 'owncloud'#localhost' (using password:YES)

I wanted to setup my owncloud installation on my raspberry pi 2. So, I created an mysql database and user.
CREATE DATABASE owncloud;
CREATE USER 'owncloud'#'localhost' IDENTIFIED BY 'Password';
GRANT ALL PRIVILEGES ON owncloud. * TO 'owncloud'#'localhost';
FLUSH PRIVILEGES;
After I type all nessesairy parameters into the webinterface of the owncloud-setup, I recevied:
Error while trying to create admin user: Failed to connect the database: An exeption occured in driver: SQLSTATE[HY000][1045] Access denied for user 'owncloud'#'localhost' (using password:YES)
Sadly, my resent sreach on similar topics didn't result in any functional hint on this problem. So, I would be happy about further suggestions.
Look at this: https://doc.owncloud.org/server/9.0/admin_manual/installation/installation_wizard.html#database-choice
In Terminal: mysql_upgrade --force -u root -p
Use administrative MySQL »root«-user and password with the Installation Wizard
Check that the Database not exist which you create with the Installation Wizard
If nothing helps, start with sqlite, then migrate to mysql like this: https://doc.owncloud.org/server/9.0/admin_manual/configuration_database/db_conversion.html
Just replace localhost for 127.0.0.1 in Owncloud's setup form for MySQL as mentioned in comments above by Askaga
For some reason, explicitly re-access the database from the terminal solves the problem for me. Just give mysql an empty line with
mysql -u root -e ";"
This should be an individual command after you created database and database user.
Sure, you should always check whether
There are users with an empty username. Remove them.
Remove "test" database.
Grant appropriate permission to your database user.
Last but not least FLUSH PRIVILEGES;.
Search other posts for instructions. I'm just providing a possible solution if you come across a situation where none of the above works.
Here's a good example to properly setup mysql after installation. FYI.
Mask the DB password in the installation screen (the password should not be visible, only dots) and retry.
Ubuntu 18.04.1, Owncloud 10.
Check the contents of config.php in my case located at /var/www/owncloud/config/.
Specialy items dbuser and dbpasswrd.
Read config.sample.php in the same directory for info.

mysql command line unable to understand how to login

I installed mysql 5.6 on windows 7(32 bit). When I open command line client 5.6 it asks me for password i put password (mysql) and press enter, it gives connection id number, meaning connection was successful.
I created a database by the name bank
create database bank;
it was created.
I created the lrngsql database user with full privileges on the bank database using following command
Grant all privileges on bank.* to 'lrngsql'#'localhost' identified by 'xyz';
It was successful too.
Now here my query begins, how do i login to this user (lrngsql).
the command i m typing in prompt
mysql>use bank;
it says
Database changed.
then i type following command to login to lrngsql
mysql -u lrngsql -p xyz;
but it gives me error. please help me what should i exactly type in order to get in to lrngsql user on bank database.
mysql -u lrngsql -p xyz;
There should be minor change to command you have used for loggin in, there should not be any space in between -p and your password.
Like
mysql -u lrngsql -pxyz;

MariaDB on Linux | Access .sql database

I'm self learning SQL. I've completed the SQLzoo course and wanted to get my hand dirty using a free Microsoft test database and MariaDB as client.
I've downloaded the database and saved it on the following path:
/usr/bin/northwind_mysql.sql
To access the database I've tried the following command but
gianluca#gianluca-Aspire-S3-391 ~ $ mysql -u gianluca -p -h localhost northwind_mysql
Enter password:
ERROR 1044 (42000): Access denied for user 'gianluca'#'localhost' to database 'northwind_mysql'
What I'm doing wrong?
Is there any clear Getting Started guide somewhere for people who don't have any experience with SQL?
I'm using it at work (MS SQL Server 2008), but I'm only querying the database with simple reading script. I would like to start learning more, for instance how to start it.
Thank you in advance.
I ran the following steps and connected successfully.
Verify connect as root
mysql -u root -p
mysql> show databases;
mysql> exit;
Download the Northwind database
Get it from here: http://code.google.com/p/northwindextended/downloads/detail?name=Northwind.MySQL5.sql
Set up the Northwind database as root
mysql -u root -p < Northwind.MySQL5.sql
Add gianluca as a user and grant permission to northwind
CREATE USER 'gianluca'#'localhost' IDENTIFIED BY 'whatevs';
GRANT ALL ON northwind.* TO 'gianluca'#'localhost';
FLUSH PRIVILEGES;
exit;
Connect as gianluca and access northwind tables
mysql -u gianluca -p
show databases;
use northwind;
show tables;
Notice that once you have created a username on localhost you don't have to specify it when connecting.

Access denied for user 'root'#'localhost' (using password: YES) (Mysql::Error)

I tried to deploy web application on my server and I am getting this mysql database exception
Access denied for user 'root'#'localhost' (using password: YES) (Mysql::Error)
I tried to access the database from the command prompt using mysql -u root -p I am able to do all the database operations.
what is the error
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:771)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3649)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1176)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at com.mpigeon.DbConnection.DbConn(DbConnection.java:26)
at com.mpigeon.CheckLoginHome.doGet(CheckLoginHome.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
You need to grant access to root from localhost. Check this ubuntu help
try using root like..
mysql -uroot
then you can check different user and host after you logged in by using
select user,host,password from mysql.user;
check you are putting blank space in password.
From my answer here, thought this might be useful:
I tried many steps to get this issue corrected. There are so many sources for possible solutions to this issue that is is hard to filter out the sense from the nonsense. I finally found a good solution here:
Step 1: Identify the Database Version
$ mysql --version
You'll see some output like this with MySQL:
$ mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrapper
Or output like this for MariaDB:
mysql Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1
Make note of which database and which version you're running, as you'll use them later. Next, you need to stop the database so you can access it manually.
Step 2: Stopping the Database Server
To change the root password, you have to shut down the database server beforehand.
You can do that for MySQL with:
$ sudo systemctl stop mysql
And for MariaDB with:
$ sudo systemctl stop mariadb
Step 3: Restarting the Database Server Without Permission Checking
If you run MySQL and MariaDB without loading information about user privileges, it will allow you to access the database command line with root privileges without providing a password. This will allow you to gain access to the database without knowing it.
To do this, you need to stop the database from loading the grant tables, which store user privilege information. Because this is a bit of a security risk, you should also skip networking as well to prevent other clients from connecting.
Start the database without loading the grant tables or enabling networking:
$ sudo mysqld_safe --skip-grant-tables --skip-networking &
The ampersand at the end of this command will make this process run in the background so you can continue to use your terminal.
Now you can connect to the database as the root user, which should not ask for a password.
$ mysql -u root
You'll immediately see a database shell prompt instead.
MySQL Prompt
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
MariaDB Prompt
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Now that you have root access, you can change the root password.
Step 4: Changing the Root Password
mysql> FLUSH PRIVILEGES;
Now we can actually change the root password.
For MySQL 5.7.6 and newer as well as MariaDB 10.1.20 and newer, use the following command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password';
For MySQL 5.7.5 and older as well as MariaDB 10.1.20 and older, use:
mysql> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('new_password');
Make sure to replace new_password with your new password of choice.
Note: If the ALTER USER command doesn't work, it's usually indicative of a bigger problem. However, you can try UPDATE ... SET to reset the root password instead.
[IMPORTANT] This is the specific line that fixed my particular issue:
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost';
Remember to reload the grant tables after this.
In either case, you should see confirmation that the command has been successfully executed.
Query OK, 0 rows affected (0.00 sec)
The password has been changed, so you can now stop the manual instance of the database server and restart it as it was before.
Step 5: Restart the Database Server Normally
The tutorial goes into some further steps to restart the database, but the only piece I used was this:
For MySQL, use:
$ sudo systemctl start mysql
For MariaDB, use:
$ sudo systemctl start mariadb
Now you can confirm that the new password has been applied correctly by running:
$ mysql -u root -p
The command should now prompt for the newly assigned password. Enter it, and you should gain access to the database prompt as expected.
Conclusion
You now have administrative access to the MySQL or MariaDB server restored. Make sure the new root password you choose is strong and secure and keep it in safe place.
I faced the same error after upgrading MySQL server from 5.1.73 to 5.5.45
There is another way to fix that error.
In my case I was able to connect to MySQL using root password but MySQL actively refused to GRANT PRIVILEGES to any user;
Connect to MySQL as root
mysql -u root -p
then enter your MySQL root password;
Select database;
use mysql;
Most probably there is only one record for root in mysql.user table allowing to connect only from localhost (that was in my case) but by the default there should be two records for root, one for localhost and another one for 127.0.0.1;
Create additional record for root user with Host='127.0.0.1' if it's not there;
SET #s = CONCAT('INSERT INTO mysql.user SELECT ',
REPLACE((SELECT GROUP_CONCAT(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'user' AND TABLE_SCHEMA = 'mysql')
,"Host","'127.0.0.1'"),
' FROM mysql.user WHERE User="root"');
PREPARE stmt FROM #s;
EXECUTE stmt;
Additionally to that you can execute mysql_upgrade -u -p
to see if everything is ok.
This error happens if you did not set the password on install, in this case the mysql using unix-socket plugin.
But if delete the plugin link from settings (table mysql.user) will other problem. This does not fix the problem and creates another problem. To fix the deleted link and set password ("PWD") do:
1) Run with --skip-grant-tables as said above.
If it doesnt works then add the string skip-grant-tables in section [mysqld] of /etc/mysql/mysql.conf.d/mysqld.cnf. Then do sudo service mysql restart.
2) Run mysql -u root -p, then (change "PWD"):
update mysql.user
set authentication_string=PASSWORD("PWD"), plugin="mysql_native_password"
where User='root' and Host='localhost';
flush privileges;
quit
then sudo service mysql restart. Check: mysql -u root -p.
Before restart remove that string from file mysqld.cnf, if you set it there.
#bl79 is the author of this answer, i've just reposted it, because it does help!
My application is using Mura CMS and I faced this issue. However the solution was the password mismatch between my mysql local server and the password in the config files. As soon as I synched them it worked.
I solved this problem by deleting the empty users creating by MySQL. I only have root user and my own user. I deleted the rest.
Update the empty password in the table mysql.user of mysql
use mysql;
select host,user,password from mysql.user;
update mysql.user set password = PASSWORD('123456') where password = '';
flush privileges;
Update user table in mysql DB. And set some password where it is blank, i was using root user so i set password for root user.
update mysql.user set password = PASSWORD('123456') where password = '';
flush privileges;
And then again tried from ATG CIM by providing password and it worked fine.
http://i.stack.imgur.com/3Lchp.png
I got this problem today while installing SugarCRM (a free CRM).
The system was not able to connect to the database using the root user. I could definitively log in as root from the console... so what was the problem?
I found out that in my situation, I was getting exactly the same error, but that was because the password was sent to mysql directly from the $_POST data, in other words, the < character from my password was sent to mysql as < which means the password was wrong.
Everything else did not help a bit. The list of users in mysql were correct, including the anonymous user (which appears after the root entries.)
I googled a lot but did not find a definite answer to my problem. I used KeyPass to generate a strong password and could use it successfully on mysql workbench to connect but not from the command line. So I changed the psw to an easy one and it worked on the command line. I have managed to create a strong password that was able to connect from the terminal. So my advise is, try with an easy password first before trying all kind of things.
I was running UTs and I started receiving error messages. I am not sure what was the problem. But when I changed my encoding style in INTELLIJ to UTF8 it started working again.
access denied for user 'root'#'localhost' (using password yes)
hibernate
this is my URL
db.url=jdbc:mysql://localhost:3306/somedb?useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8&characterEncoding=utf8
Add a user option in msyql.
GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION;
and this link will be useful.