I want to begin writing queries in MySQL.
show grants shows:
+--------------------------------------+
| Grants for #localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''#'localhost' |
+--------------------------------------+
I do not have any user-id but when I want to make a user I don't have privilleges, also I don't know how to make privileges when even I don't have one user!
mysql> CREATE USER 'parsa'#'localhost' IDENTIFIED BY 'parsa';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER pr
ivilege(s) for this operation
I tried to sign in as root:
mysql> mysql -u root -p;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-u root -p' at line 1
mysql> mysql -u root -p root;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-u root -p root' at line 1
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
I was brought here by a different problem.
Whenever I tried to login, i got that message because instead of authenticating correctly I logged in as anonymous user. The solution to my problem was:
To see which user you are, and whose permissions you have:
select user(), current_user();
To delete the pesky anonymous user:
drop user ''#'localhost';
This is something to do with user permissions. Giving proper grants will solve this issue.
Step [1]: Open terminal and run this command
$ mysql -uroot -p
Output [1]:
This should give you mysql prompt shown below
Step [2]:
mysql> CREATE USER 'parsa'#'localhost' IDENTIFIED BY 'your_password';
mysql> grant all privileges on *.* to 'parsa'#'localhost';
Syntax:
mysql> grant all privileges on `database_name`.`table_name` to 'user_name'#'hostname';
Note:
hostname can be IP address, localhost, 127.0.0.1
In database_name/table_name, * means all databases
In hostname, to specify all hosts use '%'
Step [3]: Get out of current mysql prompt by either entering quit / exit command or press Ctrl+D.
Step [4]: Login to your new user
$ mysql -uparsa -pyour_password
Step [5]: Create the database
mysql> create database `database_name`;
You might want to try the full login command:
mysql -h host -u root -p
where host would be 127.0.0.1.
Do this just to make sure cooperation exists.
Using mysql -u root -p allows me to do a a lot of database searching, but refuses any database creation due to a path setting.
If you are in a MySQL shell, exit it by typing exit, which will return you to the command prompt.
Now start MySQL by using exactly the following command:
sudo mysql -u root -p
If your username is something other than root, replace 'root' in the above command with your username:
sudo mysql -u <your-user-name> -p
It will then ask you the MySQL account/password, and your MySQL won't show any access privilege issue then on.
First, if you are unfamiliar with the command line, try using phpmyadmin from your webbrowser. This will make sure you actually have a mysql database created and a username.
This is how you connect from the command line (bash):
mysql -h hostname -u username -p database_name
For example:
fabio#crunchbang ~ $ mysql -h 127.0.0.1 -u fabio -p fabiodb
connect mysql with sudo & gives permission for the necessary user using,
sudo mysql -u user;
GRANT ALL PRIVILEGES ON database_name.* TO 'user'#'localhost';
#Nickparsa … you have 2 issues:
1). mysql -uroot -p
should be typed in bash (also known as your terminal) not in MySQL command-line. You fix this error by typing
exit
in your MySQL command-line. Now you are back in your bash/terminal command-line.
2). You have a syntax error:
mysql -uroot -p;
the semicolon in front of -p needs to go. The correct syntax is:
mysql -uroot -p
type the correct syntax in your bash commandline. Enter a password if you have one set up; else just hit the enter button. You should get a response that is similar to this:
Hope this helps!
Most Developers log-in to server(I assume you r having user-name and password for mysql database) then from Bash they switch to mysql> prompt then use the command below(which doesn’t work
mysql -h localhost -u root -p
What needs to be done is use the above command in the bash prompt--> on doing so it will ask for password if given it will take directly to mysql prompt and
then database, table can be created one by one
I faced similar deadlock so sharing the experience
I had the command correct per above answers, what I missed on was on the Workbench, where we mention 'Limit Connectivity from Host' for the user, it defaults to "%" - change this to "localhost" and it connects fine thereafter!
I'm using roles to confer least privilege on my database application users. I kept getting 'ERROR 1044 (42000): Access denied for user...' until I RTFM and discovered I had to give each user a default role(s) in order their account could be authenticated when they logged in.
#create a role
CREATE ROLE 'rolename';
#give necessary privileges to role
GRANT INSERT, UPDATE, DELETE, SELECT ON database.table TO 'rolename';
#create user
CREATE USER 'username'#'host' IDENTIFIED BY 'password';
#give the user a role(s)
GRANT 'rolename' TO 'username'#'host';
#set the user's default otherwise it's ERROR 1044
SET DEFAULT ROLE 'rolename' FOR 'username'#'host';
Related
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
So I am installing snort currently on my ubuntu linux server. I am following this guide here.
At this point, I am at the part in the guide where I am installing Barnyard2 and i need to access my SQL database to save information. linux server is near fresh install with little else on it. When I try to do this part of the guide:
echo "create database snort;" | mysql -u root -p
mysql -u root -p -D snort < ~/snort_src/barnyard2-master/schemas/create_mysql
echo "grant create, insert, select, delete, update on snort.* to \
snort#localhost identified by 'MYSQLSNORTPASSWORD'" | mysql -u root -p
When I run the first line - if I don't enter anything, I get the error message that says:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
If I do enter something, I get a different error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I have tried using this in order to reset my password but the command mysql -u root or any form of command similiar results back in the same error, even when it says the password is probably not required for this command. Does anyone know a way in which I can get this to work?
Why don't you break that down into chunks?
First make the database:
$ mysql -u root -p -e 'CREATE DATABASE `snort`'
Import the barnyard schema
$ mysql -u root -p < ~/snort_src/barnyard2-master/schemas/create_mysql
Now create the user & assign permissions for the snort db to the barnyard user
$ mysql -u root -p -e 'GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON `snort`.* TO snort#localhost IDENTIFIED BY '[SNORT PASSSWORD]'
The commands in your question are running a local mysql client which assumes to connect to a local database by default. If your database is running on a neighbouring Windows box you will need to rethink your parameters.
mysql -u root -p -h 192.168.0.99
I am trying to connect Zapier to my Database. Zapier has very limited support for this and seem to be going round in circles.
I need to GRANT SELECT to a user on my database with this code;
GRANT SELECT ON my-database-here.my-table-here TO 'user-here'#'ip-address-here' IDENTIFIED BY 'my-password-here';
The error i receive is;
#1044 - Access denied for user 'xxx'#'localhost' to database 'xxxx'
The user has ALL PRIVILEGES but can't seem to get it to work. Any help here could be greatly received.
Thanks
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
you have 2 issues:
1 => mysql -uroot -p should be typed in bash (also known as your terminal) not in MySQL
command-line. You fix this error by typing.
exit
in your MySQL command-line. Now you are back in your bash/terminal command-line.
You have a syntax error:
mysql -uroot -p;
the semicolon in front of -p needs to go. The correct syntax is:
mysql -uroot -p
type the correct syntax in your bash commandline. Enter a password if you have one set up; else just hit the enter button. You should get a response that is similar to this:
I just installed mysql on a mac and I can't seem to access any accounts from there.
I used the commands :
shell> mysql -u root -p
password:
and since I have not given one I let it go blank and I get an error saying incorrect password.
I can login using just
shell> mysql
buy I can't seem to be able to change passwords or even look at all the accounts in mysql.users.
I get the following error:
ERROR 1142 (42000): SELECT command denied to user ''#'localhost' for table 'users'
What do I do to resolve this issue and how do I use a software like sequel pro with the database?
Your problem seems, you dont have all the privileges for localhost#root, to get all the privileges run the below command.
mysql> grant all privileges on *.* to root#localhost identified by 'password' with grant option
in MySQL command prompt and you will have all the previleges to access the localhost as root.
use this command to set the password for MySQL
mysqladmin -u root password “newpassword”;
Example mysqladmin -u root password adhfhuef34;
You will also want to restart the database server after running this command
sudo /etc/init.d/mysql restart
If this Dint work, Try
$ mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
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.