How can I create a MySQL-database - mysql

I tried to create a database by the following command:
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP,
-> CREATE TEMPORARY TABLES,SHOW VIEW,CREATE ROUTINE,ALTER ROUTINE,
-> EXECUTE,CREATE VIEW,EVENT,TRIGGER
-> ON {projekti_db}.*
-> TO '{asiakas}'#'localhost';
and got the following error message
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 '{projekti_db}.*
TO '{asiakas}'#'localhost'' at line 4
I have MySQL 5.1.37. What am I doing wrong?

You are trying to assign roles to a user on a certain database. To create a database, use
CREATE DATABASE NAME;

That syntax doesn't create a database, it grants db privileges to a user.
To create a database, you'd use:
CREATE DATABASE projekti_db;
See here for a quick cheat sheet for MySQL.

#
# First create the Database
#
CREATE DATABASE projekti_db;
#
# Then Create the User that will access that database
#
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP,
CREATE TEMPORARY TABLES,SHOW VIEW,CREATE ROUTINE,ALTER ROUTINE,
EXECUTE,CREATE VIEW,EVENT,TRIGGER
ON projekti_db.*
TO 'asiakas'#'localhost';
#
# Now verify that the user asiaskas can access the projekti_db only from localhost
#
SHOW GRANTS FOR 'asiakas'#'localhost';
Give it a Try !!!

Related

CREATE USER MySQL

Error with dropping tables:
SQL query:
DROP user IF EXISTS 's01'#'%';
MySQL said: Documentation
#1064 - 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 'if exists 's01'#'%'' at line 1
Error without dropping tables:
SQL query:
/*Students*/ CREATE User 's01'#'%' IDENTIFIED BY 'pw1';
MySQL said: Documentation
#1396 - Operation CREATE USER failed for 's01'#'%'
Example of some of my code:
Drop user if exists 's01'#'%';
flush privileges;
/*Students*/
Create User 's01'#'%' Identified by 'pw1';
I don't exactly know what is wrong. I looked it up and it said add flush privileges, but I still get the same two errors.
Check your version of mysql with select version();. The IF EXISTS option for DROP USER was added in 5.7. If you're not using 5.7, then that likely explains your first error.
Check if the user exists by querying mysql.user table.
select user, host from mysql.user where user = 's01';
Also since you are not specifying a hostname, just execute
DROP user IF EXISTS 's01';
Create User 's01' Identified by 'pw1';
The wildcard host (#'%') is implied.
Also execute SHOW GRANTS to verify that your user has the correct privileges to create and drop users.

REVOKE insert on a specific table form a user in my sql

i want to revoke insert on a specific table form a user in mysql
and I try this code before:
use varian_db;
REVOKE INSERT ON 'gevhm_users' FROM 'varian_user';
but mysql returned this error :
#1064 - 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 ''gevhm_users' FROM 'varian_user'' at line 1
Please help.
You have to specify full path of database name and table name when granting or revoking privileges to/from such user. And also write user name in correct format. Your statement should like this:
REVOKE INSERT ON varian_db.gevhm_users FROM 'varian_user'#'user_ip_address';
FLUSH PRIVILEGES;
More information: MySQL Revoke Syntax

SQL database with column in the tablename

I have an error in my MySQL statement (using shell file), which I can't seem to resolve. Tried to put quotes etc but no luck. When I created it using phpmyadmin it works, but I want to have it scripted. Must be something small... Any ideas?
--- Create mySQL database ---
CREATE DATABASE IF NOT EXISTS _test-123;
CREATE USER 'test-123'#localhost IDENTIFIED BY '***';
GRANT ALL PRIVILEGES ON _test-123.* TO 'test-123'#'localhost';
FLUSH PRIVILEGES;
Enter password:
ERROR 1064 (42000) at line 1: 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 '-123' at line 1
Try removing the "-" and do this one instead-
CREATE DATABASE IF NOT EXISTS _test_123;

MYSQL error: Can't create database 'publications'; database exists

I run this command in mysql:
mysql > show databases;
My database called publications is there so I want to use it:
mysql > USE publications
But I get an error:
ERROR 1049 (42000): Unknown database 'publications'
mysql > CREATE DATABASE publications;
ERROR 1007 (HY000): Can't create database 'publications'; database exists
Have I corrupted something? It is on XAMPP on thumb drive. What does this error mean?
you may not have permissions. open up the mysql database, and double check that mysql.db table has the user you are logged in as set up to read, write, etc.. as appropriate. after changing permissions, don't forget to FLUSH PRIVILEGES

how to delete DBs from MySQL

I'm having trouble to remove MySQL Databases that's what I'm getting, I'm using 5.6 MySql
when I hit show databases:
I'm having the list of dbs such as gameserver_beta, loginserver_beta and etc however, when I use command drop database <gameserver_beta>;
I'm getting an
error 1064 (42000) yOu have an error in your SQL syntec, check the manuel that correspond to your MySQL server version ...
drop database database_name;
drop database ;
Here you did not specified any database name
try wth this