table does not exist after succesfull creation - mysql

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

Related

Cannot create table with flyway (MYSQL)

I try do create a simple mysql database with Flyway migration, but it doesn't going well.
I have created my .sql it named as V1_0__init.sql and I've written some sql commands there:
CREATE TABLE User (
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
created DATE NOT NULL,
username varchar(15) NOT NULL,
password varchar(15) NOT NULL,
email varchar(40) NOT NULL,
status boolean NOT NULL,
unique(username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I think it should be fine, but I have two errors, one at the first line (CREATE TABLE) and another at the fourth line (created DATE NOT NULL).
The error message says:
Invalid or Incomplete statement
Expected one of the following: ALGORITHM DEFINER SQL VIEW
(At the 'created DATE NOT NULL' line have a similar message, the only difference is this: Algoritm definer OR sql view)
I've tried to fix these but it didn't go well.
Anyone could help me how to fix this?
Maybe did I miss something? Should I do something in application.properties?

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
);

Syntax error, creating database

I am trying to create database android_api and table users but I am getting error
#1064 - Something is wrong in your syntax near 'use android_api
create table 'users'(
id int(11) NOT NULL primary KEY AU' w linii 3
Here is the code
create database android_api
use android_api
create table users(
id int(11) NOT NULL 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
);
You should separate each SQL statement with ;, otherwise your syntax is incorrect.
Here is the correct syntax:
create database android_api;
use android_api;
create table users(
id int(11) NOT NULL 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
);
In your code what you did was actually:
create database android_api use android_api
(Which is not a valid CREATE statement).
Actually, the accepted answer is enough. This is a very small idea to share after running into the same problem as you report it, but in a beginner's tutorial Load PostgreSQL Sample Database in an SQL Shell.
In general, if you have the reported error in an SQL shell, and if you are not sure whether you have typed ; at the end of the last line, just type ; as a new command and press Enter to be sure that you type your next command in LINE 1 and not in LINE 2.
Without this "trick", some stupidity like this can happen:
postgres=# CREATE DATABASE dvdrental
postgres-# show databases
postgres-# create database dvdrental;
ERROR: syntax error at or near »show«
LINE 2: show databases
^
postgres=# create database dvdrental
postgres-# CREATE DATABASE dvdrental;
ERROR: syntax error at or near »CREATE«
LINE 2: CREATE DATABASE dvdrental;
^
postgres=# CREATE DATABASE dvdrental;
CREATE DATABASE
Finally working, as can be seen by the output CREATE DATABASE.

SQL Error #1007

I have this #1007 error with my SQL code. When I try to import into my database it gives me this #1007 error. The data base is called company. I'm new to SQL and it would be good if someone could help me out. Thanks
CREATE DATABASE company;
CREATE TABLE login(
id int(10) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
)
It looks like the database "company" may already exist. If you look at the link provided by #Marc B, the error "#1007" corresponds to:
"Error: 1007 SQLSTATE: HY000 (ER_DB_CREATE_EXISTS)
Message: Can't create database '%s'; database exists
An attempt to create a database failed because the database already exists.
Drop the database first if you really want to replace an existing database, or add an IF NOT EXISTS clause to the CREATE DATABASE statement if to retain an existing database without having the statement produce an error."
Check your schema to make sure that you don't already have a database called "company" created.
Perhaps you are only trying to create the table "login", whereas you would simply need the code:
CREATE TABLE login(
id int(10) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
)
making sure you create this table in the already existing "company" database.
You are trying to create a database that has already been created.
Staring at your two commands, you could do CREATE TABLE IF NOT EXISTS
you also need to set default database before creating the table
CREATE DATABASE IF NOT EXISTS company;
USE company
CREATE TABLE login (
id int NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
);
or you could put the DB name before the table name
CREATE DATABASE IF NOT EXISTS company;
CREATE TABLE company.login (
id int NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
);

MySQL error 1064 - the right syntax?

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 :-)