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 :-)
Related
I am using mysql workbench in order to run basic queries that should enable me to create a new table in my database.
The code that I am trying to run is:
DROP TABLE IF EXISTS airbnb.neighborhood;
CREATE TABLE airbnb.neighborhood (
nbh_id INT PRIMARY KEY NOT NULL,
nbh_name VARCHAR(45) NOT NULL,
);
The error that I got is :
Error Code: 1064. You have an error in your SQL syntax; check the manual that c....
I cannot see any syntax error here, but it is giving me a red line under 'CREATE'.
It says
) is not valid at this point. Expecting an identifier
I checked other questions/SO articles with this message but they are all talking about solving different syntactical errors, so did not really help me.
Please assist, and thank you very much for your help!
You need a semicolon at the end of the DROP TABLE line, i.e.
DROP TABLE IF EXISTS airbnb.neighborhood;
CREATE TABLE ....
This is because DROP TABLE and CREATE TABLE are two separate SQL statements. The semicolon marks the end of the first statement and allows you to start the second.
CREATE TABLE airbnb.neighborhood (
nbh_id INT NOT NULL,
nbh_name VARCHAR(45) NOT NULL,
PRIMARY KEY (nbh_id)
);
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
This question already has answers here:
How to execute multiple SQL queries in MySQL Workbench?
(2 answers)
Closed 5 years ago.
I am trying to run SQL on phpmyadmin but gettin tis error, and can't find what's wrong in it.
1064 - 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 'use android_api /** Selecting Database **/
My code below:
create database android_api /** Creating Database **/
use android_api /** Selecting Database **/
create table users(
id 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 **/
Remove use android_api . You don't need to have that.
USE statement is only use for each time you begin a mysql session.
Assume android_api have created and you have log out mysql. When you log in again, then only you need to use USE statement.
Edit
Need a space between users and (
create table users (
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
);
I am a little embarrassed asking this question but I seem to be stumped.
I am using MySQL 5.7 and am trying to upload to my online server which has MySQL 5.6. phpMyAdmin was used create the database. I get the same error when I try to restore the database in my local phpMyAdmin (part of my WAMP server).
I have also studied the My SQL reference documentation as well as several internet searches. Here is the error:
SQL query:
DROP TABLE IF EXISTS `heyx1_assets`;
CREATE TABLE `heyx1_assets` (
`id` int(10) UNSIGNED NOT NULL COMMENT 'Primary Key',
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT
) ;
MySQL said:
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 ')' at line 4
Any help will be appreciated. My client is becoming very impatient.
You have a COMMENT, but no comment. You need a string after COMMENT:
CREATE TABLE `heyx1_assets` (
`id` int(10) UNSIGNED NOT NULL COMMENT 'Primary Key',
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Comment goes here'
---------------------------------------------------^
) ;
Which phpMyAdmin versions are you using on each server? This seems like it may have been a bug with an older version of phpMyAdmin (which had trouble exporting in a similar way to what you're describing); I suggest you upgrade to the latest (which is currently 4.6.5.2).
You can also edit the SQL file to manually fix the COMMENT as shown by Gordon Linoff.