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
the Tin Man
158k42 gold badges214 silver badges303 bronze badges
asked Jan 12, 2012 at 16:44
12
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.
answered Jan 12, 2012 at 16:58
NowhyNowhy
2,8741 gold badge16 silver badges13 bronze badges
8
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
the Tin Man
158k42 gold badges214 silver badges303 bronze badges
answered Aug 12, 2012 at 11:16
soleshoesoleshoe
1,2052 gold badges11 silver badges16 bronze badges
3
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';
answered May 22, 2013 at 8:50
Lefteris ELefteris E
2,7861 gold badge24 silver badges23 bronze badges
4
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`;
answered Jan 23, 2018 at 9:15
theBuzzyCodertheBuzzyCoder
2,6322 gold badges31 silver badges26 bronze badges
5
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.
the Tin Man
158k42 gold badges214 silver badges303 bronze badges
answered Jun 23, 2012 at 4:46
RayRay
1111 silver badge2 bronze badges
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.
Adrian Mole
49.5k155 gold badges49 silver badges80 bronze badges
answered Feb 26, 2014 at 5:49
Kshitij MittalKshitij Mittal
2,6483 gold badges25 silver badges40 bronze badges
2
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
fedorqui
273k103 gold badges545 silver badges595 bronze badges
answered Dec 22, 2012 at 22:44
fabiog1901fabiog1901
3423 silver badges12 bronze badges
1
connect mysql with sudo & gives permission for the necessary user using,
sudo mysql -u user;
GRANT ALL PRIVILEGES ON database_name.* TO 'user'@'localhost';
answered Apr 20, 2021 at 5:09
@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!
1
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
answered Jul 9, 2013 at 14:03
DevrathDevrath
41.9k54 gold badges195 silver badges292 bronze badges
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!
answered Feb 24, 2016 at 15:35
killjoykilljoy
9101 gold badge11 silver badges16 bronze badges
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';
answered Apr 6, 2022 at 15:08
ClariusClarius
1,16310 silver badges9 bronze badges
I tried a lot to import the sql script to create database and tables through phpmyadmin in the new site I hosted. But i’m getting the error,
1044 — Access denied for user ‘user’@’localhost’ to database ‘db’
I tried to create a sample db directly : create database sampled; I’m getting the same access denied error.
I’m not able to grant privileges to the user also, i’m getting the same access denied error.
Following is the output of show grants command,
show grants;
GRANT USAGE ON . TO 'someuser'@'localhost' IDENTIFIED BY PASSWORD 'somepw'
GRANT ALL PRIVILEGES ON someuser_%.* TO 'someuser'@'localhost'
Any help would be appreciated. thank you.
asked Jan 30, 2014 at 4:24
1
If you are using Godaddy then don’t directly go to phpMyAdmin and run the sql command.
You have to go to MySQL® Databases section and create a database there.
Then create a user and give it the permission to access the database you just created.
Now you can go to phpMyAdmin and write your SQL commands.
Hope this helps
answered Dec 16, 2015 at 19:01
55110022335511002233
4938 silver badges19 bronze badges
This error can be avoided in the beginning when creating the user account
. Following commands must be used to create user account
having all the PRIVILEDGES
.
CREATE USER 'demouser'@'localhost' IDENTIFIED WITH mysql_native_password BY '***';
GRANT ALL PRIVILEGES ON *.* TO 'demouser'@'localhost' WITH GRANT OPTION;
ALTER USER 'demouser'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
CREATE DATABASE IF NOT EXISTS 'demouser';
GRANT ALL PRIVILEGES ON `demouser`.* TO 'demouser'@'localhost';
answered Aug 3, 2022 at 17:22
1
It is clear that the user someuser
do not have proper privilege over the database db
. You need to grant privileges for the user over the database to correct this issue.
If you do bot have administrative rights contact your admin for granting privileges to someuser
on that db
answered Jan 30, 2014 at 4:28
Abdul ManafAbdul Manaf
4,7603 gold badges27 silver badges34 bronze badges
For me the problem is I’m not having permissions to Create new Databasename or even Modify the name of the Database. You can contact your admin to avail privileges or if you want to quickly import the .sql
file… then you can open the .sql file with text editor and find the following line:
CREATE DATABASE IF NOT EXISTS `enter the existing db name` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `enter the existing db name`;
After that try to import the .sql
file…now you can successfully import all the tables!
answered May 7, 2018 at 13:29
BharathRaoBharathRao
1,8161 gold badge17 silver badges28 bronze badges
I had the same problem i solve it buy change the GRANTEE and made the user he can do all the operation in PhpMyAdmin ,follow the steps :
-
Enter to mysql in root permission but :
sudo mysql
Enter the password, and type this :SELECT * FROM information_schema.user_privileges;
And see the user in IS_GRANTABLE is he yes or no.
If he yes then see the PRIVILEGE_TYPE what it might it be just tow operation if it’s true add the last operations.
and see this link to change IS_GRANTABLE from no to yes.
I wish this could help you.
answered Mar 7, 2020 at 11:28
Must Ensure that your User_Name, Password and Database name are correct.
If you are Deal with database ‘sampled’ then type ‘sampled’ in query instead of ‘db’ also must ensure that you don’t have to use quota(‘) in Statement.
answered Mar 29, 2017 at 2:49
you have not exported database from localhost or from web server correctly follow these steps go to localhost database click export tab than select ‘Custom — display all possible options ‘check box few options will open in section ‘output’ change compression none to zipped and now click go button at bottom it will properly export your database you can now import to hosting or anywhere you want with no errors
answered Mar 31, 2016 at 22:51
I started getting this error message for no reason at all. Solved by using MySQL and the Server menu option;
Selected my bitnami_wordpress schema;
selected the bn_wordpress user;
then picked the Administrative Roles
tab and granted access to this user. I had to do this to all of the users that the access was removed from.
Andrew
1,7351 gold badge21 silver badges29 bronze badges
answered Mar 4, 2021 at 16:02
Linux, Программное обеспечение
- 05.05.2019
- 6 800
- 1
- 3
- 3
- 0
- Содержание статьи
- Описание
- Исправляем ошибку
- Способ (быстрый)
- Способ (чуть дольше)
- Комментарии к статье ( 1 шт )
- Добавить комментарий
В данной статье пойдет речь об ошибке 1044 Access denied when using LOCK TABLES, которую вы можете получить при попытке создать резервную копию с помощью утилиты mysqldump.
Описание
Полностью текст ошибки выглядит следующим образом:
mysqldump: Got error: 1044: Access denied for user ‘user’@’localhost’ to database ‘database_name’ when using LOCK TABLES
Как видно из текста ошибки, проблема заключается в том, что пользователь, под которым вы пытаетесь сделать резервную копию, не обладает правами на «LOCK TABLES». Вот что говорит мануал, по этому поводу:
mysqldump requires at least the SELECT privilege for dumped tables, SHOW VIEW for dumped views, TRIGGER for dumped triggers, and LOCK TABLES if the —single-transaction option is not used. Certain options might require other privileges as noted in the option descriptions.
For each dumped database, lock all tables to be dumped before dumping them. The tables are locked with READ LOCAL to permit concurrent inserts in the case of MyISAM tables. For transactional tables such as InnoDB, —single-transaction is a much better option than —lock-tables because it does not need to lock the tables at all.
Because —lock-tables locks tables for each database separately, this option does not guarantee that the tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states.
Исправляем ошибку
Как видно из описания, решить данную проблему можно как минимум двумя разными способами.
Способ (быстрый)
Достаточно добавить к mysqldump аргумент --single-transaction
, т.е. целиком команда для создания резервной копии будет выглядеть примерно так:
mysqldump -u user -p --single-transaction database_name > database_backup.sql
Способ (чуть дольше)
Необходимо просто выдать тому пользователю (в нашем примере «user»), под которым мы пытаемся создать резервную копию права на «LOCK TABLES» на ту базу(-ы), резервную копию которой(-ых), мы пытаемся создать. Для этого, необходимо подключиться под учетной записью root к MySQL серверу и выдать нужные права. Делается это следующим образом:
1) Подключаемся к MySQL серверу под учетной записью root
mysql -u root -p
2) Выдаем нужные права для пользователя, под которым мы пытаемся сделать резервную копию
GRANT LOCK TABLES ON database_name.* TO 'user'@'localhost';
database_name
— название базы данных, резервную копию которой вы пытаетесь сделать, необходимо поменять на то, которое подходит для вашего случая.
user
— имя пользователя под которым вы пытаетесь сделать резервную копию, необходимо поменять на то, которое подходит для вашего случая.
3) Отключаемся
exit;
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
the Tin Man
158k42 gold badges214 silver badges303 bronze badges
asked Jan 12, 2012 at 16:44
12
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.
answered Jan 12, 2012 at 16:58
NowhyNowhy
2,8741 gold badge16 silver badges13 bronze badges
8
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
the Tin Man
158k42 gold badges214 silver badges303 bronze badges
answered Aug 12, 2012 at 11:16
soleshoesoleshoe
1,2052 gold badges11 silver badges16 bronze badges
3
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';
answered May 22, 2013 at 8:50
Lefteris ELefteris E
2,7861 gold badge24 silver badges23 bronze badges
4
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`;
answered Jan 23, 2018 at 9:15
theBuzzyCodertheBuzzyCoder
2,6322 gold badges31 silver badges26 bronze badges
5
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.
the Tin Man
158k42 gold badges214 silver badges303 bronze badges
answered Jun 23, 2012 at 4:46
RayRay
1111 silver badge2 bronze badges
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.
Adrian Mole
49.5k155 gold badges49 silver badges80 bronze badges
answered Feb 26, 2014 at 5:49
Kshitij MittalKshitij Mittal
2,6483 gold badges25 silver badges40 bronze badges
2
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
fedorqui
273k103 gold badges545 silver badges595 bronze badges
answered Dec 22, 2012 at 22:44
fabiog1901fabiog1901
3423 silver badges12 bronze badges
1
connect mysql with sudo & gives permission for the necessary user using,
sudo mysql -u user;
GRANT ALL PRIVILEGES ON database_name.* TO 'user'@'localhost';
answered Apr 20, 2021 at 5:09
@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!
1
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
answered Jul 9, 2013 at 14:03
DevrathDevrath
41.9k54 gold badges195 silver badges292 bronze badges
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!
answered Feb 24, 2016 at 15:35
killjoykilljoy
9101 gold badge11 silver badges16 bronze badges
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';
answered Apr 6, 2022 at 15:08
ClariusClarius
1,16310 silver badges9 bronze badges
Ошибка возникает когда импортирую базу с локального диска.
SQL запрос:
CREATE TABLE `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) DEFAULT NULL,
`meta_value` longtext,
PRIMARY KEY (`meta_id`),
KEY `comment_id` (`comment_id`),
KEY `meta_key` (`meta_key`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Ответ MySQL: Документация
#1044 - Для пользователя 'id5570277_zudi'@'%' доступ к базе данных 'information_schema' закрыт