I am new to MySQL and in the learning curve ,
I wanted somehelp ..
I tried importing the temp database from https://github.com/datacharmer/test_db ... I am having diffulties in importing the same .
I think I have wrongly imported and I wanted to drop the table , But its not allowing me .
I get the below error .
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| #mysql50#test_db-master |
+-------------------------+
5 rows in set (0.00 sec)
I am not getting any response in Terminal , but when I tried in MySQL Workbench , I am getting the below error
*drop '#mysql50#test_db-master'
22:04:30 drop '#mysql50#test_db-master' Error Code: 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 ''#mysql50#test_db-master'' at line 1 0.00034 sec*
I wanted to delete this table & wanted to create a new one again ...
https://dev.mysql.com/doc/refman/5.7/en/drop-database.html shows the syntax for DROP DATABASE.
Pro tip: Read documentation. You can get answers more quickly than by posting on Stack Overflow.
Related
So i created a database in MySQL Workbench and I am trying to view them on the MySQL Command Line Client because i want to do my queries there instead of the workbench.
Here's whats happening:
mysql> use policestation(crime);
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_policestation(crime) |
+--------------------------------+
| accused |
| case |
| complainant |
| investigation_officer |
| outcome |
| section_of_law |
+--------------------------------+
6 rows in set (0.04 sec)
mysql> select * from case;
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 'case' at line 1
The same query works fine in MySQL Workbech. Also it works for all other tables in Command Line Client.
It's b/c Case is a MySQL reserved keyword: https://dev.mysql.com/doc/refman/5.5/en/keywords.html
You'll need to seround reserved keywords with tick marks not quotes.
Example:
SELECT * FROM `case`
Not the same as
SELECT * FROM 'case'
Also here is another helpful link:
Syntax error due to using a reserved word as a table or column name in MySQL
i have installed Server version: 5.6.25 MySQL Community Server (GPL) on my laptop with OS ubuntu 14.04 lts. Recently i tried to run mysqlimport client program and got errors that i was unable to figure out.
on terminal i type this command and got this error:
mysql> mysqlimport --local test_database employee.txt;
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 'mysqlimport --local test_database employee.txt' at line 1
Initially, i thought that may be the problem is in the employee.txt file directory which i stored under var/lib/mysql directory.But when i tried this most basic mysqlimport command i again got error!:
mysql> mysqlimport --help;
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 'mysqlimport --help' at line 1
Thus, i think my current mysql 5.6.25 does not have mysqlimport support.I tried to follow this RPM Package Client Utilities..However that was for linux not ubuntu & all the given Package versions are 5.6.26 not 5.6.25.BTW all of my other configurations such as phpmyadmin & database query works fine.
Therefore, in that situation how should i resolve the problem ?
let me know for further information.
Thanks
Thanks alvits , finally i tried this modified commands from outside the mysql in another terminal:
mysqlimport --local -u root -p test_database home/himadree/mysqlTestingFiles/employee.txt;
it works,BUT the data inside the employee.txt were not correctly restored into the table. my actucal employee.txt contains this tab-dalimated data below:
100 John Doe DBA
200 John Smith Sysadmin
300 Raj Patel Developer
But after mysqlimport command i got this output:
select * from employee;
+-------+-----------------+------+
| empno | ename | job |
+-------+-----------------+------+
| 100 | John Doe | NULL |
| 200 | NULL | NULL |
| 300 | NULL | NULL |
+-------+-----------------+------+
3 rows in set (0.00 sec)
why i m getting some incorrect data on the table?
Yes Finally i realized that there were some extra tabs in the text file & last commands were fine.
Now here is my final table:
mysql> select * from employee;
+-------+------------+-----------+
| empno | ename | job |
+-------+------------+-----------+
| 100 | John Doe | DBA |
| 200 | John Smith | Sysadmin |
| 300 | Raj Patel | Developer |
+-------+------------+-----------+
So, anyone trying to learn the mysqlimport program then be careful:
whether the input text file properly delimited or not.
use mysqlimport program outside from mysql program itself with opening another terminal/shell on your OS etc.
Thanks a lot.
In Ubuntu, shell, I ditched mysqlimport and instead use:
MYSQL -h blah < file.sql
This is mysql table:
+---------------------+
| Tables_in_myproject |
+---------------------+
| reds |
| zxy |
| abcd |
| release |
+---------------------+
4 rows in set (0.46 sec)
When I try to select or show release table it throws the following error:
mysql> select * from release;
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 'release' at line 1
What am I doing wrong? I am able to select all the other tables.
release is a reserved keyword in MySQL and needs to be escaped by backticks.
select * from `release`;
release is a reserved word. use backticks arround or better change the table name.
select * from `release`;
How can i drop a database containing the "-" symbol?
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| vms01 |
| vms-0.1.0 |
+--------------------+
4 rows in set (0.00 sec)
mysql> drop database vms-0.1.0;
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 n
ear '-0.1.0' at line 1
mysql>
You can quote identifiers (for example table and column names) with backticks:
drop database `vms-0.1.0`
See the documentation for more details: Schema Object Names.
The identifier quote character is the backtick ("`"):
I am trying to update 'pwd' column of 'Goal' table using following mysql query but sad thing is it gives error. mysql query:
UPDATE Goal
SET pwd = (SELECT MD5(CONCAT(ID, LEFT(phone,3), '$='))
FROM Esubmission);
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 'FROM Esubmission)' at line 1
My tables are like below;
Esubmission
ID | pnone | email |
--------------------------------------------
20378 | 00000000000 | someone#gmail.com|
20379 | 00000000000 | someone#gmail.com|
20380 | 00000000000 | someone#gmail.com|
Goal
usr | pwd | time|
--------------------
20378 | |12:09|
20379 | |15:29|
20380 | |15:47|
Hmm.... I'm thinking that you really want to set the password for each user (I think), in which case you'll need to have a join for the update, and that way you can eliminate your multiple values you are selecting.. because the way you have it, you're updating all the values in the Goal table for pwd to the same value... the way below, you update each users pwd to be based on the row joined with the ID. Assuming you have one row for each usr in the esubmission table, this should work:
UPDATE Goal
SET pwd = MD5(CONCAT(ID, LEFT(e.phone,3), '$='))
FROM Goal g, Esubmission e
where e.ID = g.usr
I tested it here and worked fine. MySQL 5.1.37