SQL error on ubuntu command line - mysql

I am working with a SQL database on a Ubuntu LAMP server. I am attempting to create a new database then a new table in it, which can hold blobs. I can login, create my database, use it, but then I cannot create the table. I am doing:
$mysql -u root -p mypass
mysql> use frame;
Database changed
mysql> create table 'frame_info' ( 'frame_data' BLOB NOT NULL, 'frame_name' VARCHAR(45) NULL, 'creator_name' VARCHAR(45) NULL, PRIMARY KEY ('frame_data'));
From there, I get the error:
ERROR 1064 (4200): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to user near ''fram
e_info' ( create table 'frame_info' ( 'frame_data' BLOB NOT NULL, 'frame_na' at
line 1
Obviously that error is truncated by the mysql display, but you get the gist.

You should use backticks ` instead of single quotes ' or (in your case) you can succeed without them at all :
create table `frame_info` (
`frame_data` BLOB NOT NULL,
`frame_name` VARCHAR(45) NULL,
`creator_name` VARCHAR(45) NULL,
PRIMARY KEY (`frame_data`)
);

Related

Error 1064 when importing SQL generated from MySQL Workbench forward engineering

I am trying to import a schema into MySQL (MariaDB 10.1.36) and I am getting the above error. I also tried direct forward engineering in MySQL Workbench but the results are the same.
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')
ENGINE = InnoDB
Sample code that fails is:
CREATE TABLE IF NOT EXISTS `example`.`adhere` (
`adhere_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`description` VARCHAR(100) NOT NULL,
`id_uuid` VARCHAR(36) NULL,
PRIMARY KEY (`adhere_id`),
INDEX `ix_tmp_autoinc` (`adhere_id` ASC) VISIBLE)
ENGINE = InnoDB
AUTO_INCREMENT = 19
DEFAULT CHARACTER SET = latin1;
I tried changing the backticks into single quotes in vain, I later removed them to same result. The expectation is to have the table created so do the rest structured like so.
remove the VISIBLE word
DEMO
CREATE TABLE IF NOT EXISTS `example`.`adhere`
(
`adhere_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`description` VARCHAR(100) NOT NULL,
`id_uuid` VARCHAR(36) NULL,
PRIMARY KEY (`adhere_id`),
INDEX `ix_tmp_autoinc` (`adhere_id` ASC)
)
Check that your version of mariadb supports invisible/visible indexes here https://mariadb.com/kb/en/library/invisible-columns/ and if not turn off the option in mysql workbench here https://dev.mysql.com/doc/workbench/en/wb-table-editor-indexes-tab.html

mySQL - cannot create table

I have this SQL code I have used on another server to create a table if it doesn't exist. It has always worked perfectly. Today I decided to install mySQL on my own computer and use the same script, but this time I get an error. I have tried to rewrite the code in case there are any compatibility issues, however, without any success...
The SQL code:
$table = "Test";
$sql = "CREATE TABLE IF NOT EXIST $table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Email VARCHAR(50) NOT NULL,
Country VARCHAR(50) NOT NULL,
Date TIMESTAMP
)";
This is the error message i receive:
Error creating table: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXIST Test ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, ' at line 1
I tried to create a new table manually in phpMyAdmin and simply copy the generated SQL code to my PHP-script and create a table that way. It didn't work either...
It's mariaDB on a Kali computer:
mysql version 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (i686) using readline 5.2
Any ideas?
I think you have made one spelling mistake in EXIST should write like EXISTS
Please re write your query as
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Email VARCHAR(50) NOT NULL,
Country VARCHAR(50) NOT NULL,
Date TIMESTAMP
)";
this will surely work in your case please try this.

mysql - Error 1064

I have a problem with MySQL.
I had successfully set up MySQL, as well as created a database (named "Users").
I am able to CREATE DATABASE (such as the one named "Users"), but when I'm onto creating tables using the command CREATE TABLE, MySQL returns the statement:
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 'NOT NULL, password NOT NULL)' at line 2
Here's my code:
-- First, I'll set the database to "Users":
USE users
-- Then, I'll make a table within the database Users:
CREATE TABLE users (
user NOT NULL,
password NOT NULL
);
Your syntax for creating a table in MySQL is not correct. You have to provide the data type for every column you create inside a table, Like if your user and password is varchar type then:
CREATE TABLE users (
user VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL
);
Also read link for reference.
You miss the data type for your columns, try this one (obviously you can change the column type as for your requirements):
CREATE TABLE users (
user VARCHAR(24) NOT NULL,
password VARCHAR(24) NOT NULL
);

Running SQL script gives syntax error

I have written an sql script with the following contents :
CREATE DATABASE IF NOT EXISTS stock_trading;
USE stock_trading;
CREATE TABLE IF NOT EXISTS transactions(
user_name VARCHAR(30) NOT NULL,
passwrd BINARY(64) NOT NULL,
balance_cash BIGINT NOT NULL DEFAULT 100000,
PRIMARY KEY (user_name,passwrd),
)ENGINE=InnoDB;
and every time I try to run it in the SQL command prompt it keeps giving away the error as:
ERROR 1064 (42000) at line 5 in file: 'db_script.sql': You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')ENGINE=InnoDB' at line 5
the script appears to be correct but I don't know why it keeps giving this error.
Additional information:
Operating System : Arch Linux
Database : MariaDB
You have a stray comma at the end of your table definition:
PRIMARY KEY (user_name,passwrd),
^^^ remove this
Your full table definition:
CREATE TABLE IF NOT EXISTS transactions(
user_name VARCHAR(30) NOT NULL,
passwrd BINARY(64) NOT NULL,
balance_cash BIGINT NOT NULL DEFAULT 100000,
PRIMARY KEY (user_name, passwrd)
) ENGINE=InnoDB;

Use MySQL in command prompt, ERROR 1064 (42000) occur when creating table

I am using xampp.
After creating a database
CREATE DATABASE University + use University
I create table by typing
CREATE TABLE Student
(
SNo INT NOT NULL,
SName VARCHAR(16) NOT NULL,
SAge INT NOT NULL,
SDepartment ENUM('CS', 'EE', 'Math', 'Physics') NOT NULL,
PRIMARY KEY (SNo)
);
But a beep is resulted and
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 'use University
CREATE TABLE Student
(
SNo INT NOT NULL,
Sname VARCHAR(16) NOT NULL,
SAg'
at line 2
is shown in command prompt. But I don't know what the syntax error is in this case.
I think the + is giving you syntax error. Try getting rid of it to separate these into two statements
CREATE DATABASE University
USE University