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
);
Related
I used MySQL through command line in order to create a database named javafxsample. The code is as folls:
create database javafxsample;
use javafxsample;
create table if not exists user(
id int(11) not null auto_increment,
username varchar(255) not null unique,
last_name varchar(255) not null,
first_name varchar(255) not null,
password varchar(255) not null,
created_at datetime not null default current_timestamp,
primary key(id)
);
The database javafxsample is created successfully in MySQL command line. (I know this because I can see it using SHOW DATABASES;.) However, when I try to see it using DESCRIBE javafxsample;, I got this error message:
ERROR 1146 (42S02): Table 'javafxsample.javafxsample' doesn't exist.
I do not know how to solve this issue, nor why I can not see the table javafxsample. I am using MySQL server version 5.7.24. Any help or suggestion(s) in order to get this table work is really appreciated.
javafxsample is your database. you cannot use describe on database.
Try describe user instead
The error "ERROR 1146 (42S02): Table 'javafxsample.javafxsample' doesn't exist" says table "javafxsample" does not exists in "javafxsample" database.
You create database "javafxsample" and table "user".
So try describing your user table like DESCRIBE user
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;
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`)
);
IF COL_LENGTH('Characters', 'name') IS NULL
BEGIN
ALTER TABLE `Characters` ADD `name` INT(32) UNSIGNED NOT NULL;
END
I am trying to write some sql that will insert a column name into the table "Characters" if it is not already existant, however I am getting errors which I do not understand (quite new to SQL) and I could use some help understanding why it is not working. I have gotten the IF part from another Question, and the ALTER part from the DBMS I'm using, PhpMyAdmin 2.11.4.
It is using MySQL 5.6 apparently and this is the error:
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 COL_LENGTH('Characters', 'name') IS NULL
BEGIN
ALTER TABLE `Characters` AD' at line 1
I am very new to MySQL so before you decide to downvote this please just add a comment and I will delete the post. I am following a tutorial on android-hive, http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/, that uses MySQL as a database for holding user information. I set up MySQL on an AWS EC2 Linux instance, along with apache tomcat etc. etc. The tutorial says:
Open your mysql console or phpmyadmin and run following query to create database
and users table:
create database android_api /** Creating Database **/
use android_api /** Selecting Database **/
create table users(
uid int(11) primary key auto_increment,
unique_id varchar(23) not null unique,
name varchar(50) not null,
email varchar(100) not null unique,
encrypted_password varchar(80) not null,
salt varchar(10) not null,
created_at datetime,
updated_at datetime null
); /** Creating Users Table **/
I connect to my Linux instance via SSH and start MySQL and run the query that is stated in the tutorial. I get the following error:
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 android_api
create table users(
uid int(11) primary key auto_increment,
' at line 3
I really have no idea how to solve this and I appreciate any help given, thank you for your time.
seems like you have missed the statement separator. try and use ";" at the end of each query.
In your code there is
use android_api //this one is correct
but in error message the quote is
uses android_api
so it looks like this code is not exactly same that You have problem with.
If anyone encounters this in the future. The solution is to use the create database query first, then after creation of the database use the "use" query and the create table query together.
there is a syntex mistake use ";" after second statement like
use android_api;
it worked for me :-)