0

I am very new to MySQL. I have an SQL file called tables.sql as shown below.

I uploaded it to a subfolder in my public_html folder.

When I copy the below into a MySQL query and run it, I get this error: "Documentation #1046 - No database selected".

How can I execute this to create a table? When I go to http://mywebsite.com/subfolder/tables.sql it says Page not found

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(100) NOT NULL AUTO_INCREMENT,
  `fullname` varchar(200) NOT NULL,
  `username` varchar(100) NOT NULL,
  `email` varchar(200) NOT NULL,
  `password` varchar(100) NOT NULL,
  `gender` varchar(100) NOT NULL,
  `photo` varchar(200) NOT NULL,
  `businessname` text NOT NULL,
  `telephone` varchar(200) NOT NULL,
  `country` varchar(100) NOT NULL,
  `confirmed` varchar(100) NOT NULL,
  `registered_date` varchar(200) NOT NULL,
  `last_visited` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;



INSERT INTO `users` (`id`, `fullname`, `username`, `email`, `password`, `gender`, `photo`, `businessname`, `telephone`, `country`, `confirmed`, `registered_date`, `last_visited`) VALUES
(1, 'Vasplus Blog', 'vasplus', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'vasplus.gif', 'Vasplus Programming Blog', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013'),
(2, 'Victor Olu', 'victor', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'victor.gif', 'Vasplus Blog', '', 'Malaysia', 'yes', '05-05-2013', '05-05-2013'),
(3, 'Greg Joshua', 'greg', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'c.jpg', 'Vasplus Programming Blog', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013'),
(4, 'Emy Nero', 'pretty', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Female', 'd.jpg', 'Vasplus Programming Blog', '', 'Italy', 'yes', '05-05-2013', '05-05-2013'),
(5, 'Victor Barack', 'barack', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'b.jpg', '', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013'),
(6, 'Chin Shi Hong', 'chin', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'a.jpg', '', '', 'Malaysia', 'yes', '05-05-2013', '05-05-2013'),
(7, 'Sydney Odell', 'ney', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Female', 'e.jpg', '', '', 'China', 'yes', '05-05-2013', '05-05-2013'),
(8, 'Engineer Bob', 'bobby', 'vasplusblog@gmail.com', '81dc9bdb52d04dc20036dbd8313ed055', 'Male', 'bobby.jpg', '', '', 'United States of America', 'yes', '05-05-2013', '05-05-2013');




CREATE TABLE IF NOT EXISTS `vpb_pms` (
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `touser` varchar(40) NOT NULL,
  `fromuser` varchar(40) NOT NULL,
  `subject` text NOT NULL,
  `message` text NOT NULL,
  `read` enum('0','1') NOT NULL DEFAULT '0',
  `deleted` enum('0','1') NOT NULL DEFAULT '0',
  `datesent` varchar(200) NOT NULL,
  `outdel` enum('0','1') NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



CREATE TABLE IF NOT EXISTS `vpb_pms_attachments_main` (
  `id` int(100) NOT NULL AUTO_INCREMENT,
  `uid` varchar(200) NOT NULL,
  `from` varchar(200) NOT NULL,
  `to` varchar(200) NOT NULL,
  `file` varchar(200) NOT NULL,
  `date` varchar(200) NOT NULL,
  `delete` varchar(200) NOT NULL,
  `outdelete` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



CREATE TABLE IF NOT EXISTS `vpb_pms_attachments_temporal` (
  `id` int(100) NOT NULL AUTO_INCREMENT,
  `uid` varchar(200) NOT NULL,
  `from` varchar(200) NOT NULL,
  `to` varchar(200) NOT NULL,
  `file` varchar(200) NOT NULL,
  `date` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
luchaninov
  • 6,792
  • 6
  • 60
  • 75

3 Answers3

1

Connect to the MySQL Client, and when you have authenticated yourself, and created the database (create database [database name];) then just execute the script with the command:

\. tables.sql

Krazick
  • 320
  • 2
  • 4
0

If your database was not created, create it first like this:

mysqladmin -uroot -p myRootPassword create myDatabaseName

If root has no password setup, forget the -p myRootPassword

Then run the following command from your the command line, being in your public_html folder:

mysql -u root -p myRootPassword mydatabaseName < tables.sql

Replace myRootPassword by your mysql root password and mydatabaseName by your database name.

If root has no password setup run it like this:

mysql -u root -p myRootPassword mydatabaseName < tables.sql
Cedric Simon
  • 4,571
  • 4
  • 40
  • 52
0

The geeky approach:

Step 1. Create your database:

mysql -h yourHost -u yourUser -pYourPassword -e"create database dbName";

(if you are working on localhost, you can omit the -h yourHost piece.

Step 2. Load your file on the newly created database:

mysql -h yourHost -u yourUser -pYourPassword dbName < tables.sql
Barranka
  • 20,547
  • 13
  • 65
  • 83