type :

mysql -u root -p

it will prompt for password

you enter password

after that select a database but before run

SHOW DATABASES;

to view availabe databases

alternatively you want to create a new db e,g :

CREATE DATABASE products;

then select a database :

USE products

then you can execute your script in-cli like :

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `username` varchar(100) NOT NULL,
  `password` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

in one line :

CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `username` varchar(100) NOT NULL, `password` varchar(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

you can also do :

mysql db_name < text_file

or

mysql < text_file

if USE db_name; is the first statement in the file.

 

 

Advertisements