LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2003, 07:07 AM   #1
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Rep: Reputation: 32
mysql via shell help needed


Hi guys

i've worked out how to create a database, show a database, and drop a database.

I've been trying to inport a sql file into a sql database.but it dont seem to work.
I got told to source the file with in the dir the sql file sit's.
mysql> source /home/tommytomato/downloads/nuke.sql

here is what i've done.

[root@www bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 32 to server version: 3.23.58

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)

mysql> create database nuke;
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| nuke |
| test |
+----------+
3 rows in set (0.00 sec)

mysql> \q
Bye
[root@www bin]# mysqladmin -u root -p drop nuke
Enter password:
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'nuke' database [y/N] y
Database "nuke" dropped
[root@www bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 34 to server version: 3.23.58

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)

mysql>

that was the test add show and drop, so that works.
now the bit i got told i dont quiet understand.

Quote:
At this prompt, type 'source thesqlfile.sql'

That will run the sql file. If the sql file doesn't have a use statement at the top of the file (use databasename)
then you need to type that before sourcing it. Also, when you run this command, be in the directory where the sql
file is residing at the moment (to avoid having to type a whole path to the sql file).

Hopefully that was clear enough, if it fails because of 'no database selected' then just issue a 'use foo;'
command (use databasename).


is the source the path to were the sql sits.

[root@www root]# cd /home/tommytomato/downloads
[root@www downloads]# ls
nuke.sql


any one tune me up abit please.

tommytomato
 
Old 12-01-2003, 07:50 AM   #2
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
I'm not entirely sure what you are trying to do, but if you are trying to run a series of sql commands in an external file, I tend to do it a bit differently using redirection:

#>mysql -u hangdog -p </path/to/mysqlscript.sql


Once I type in my password, the script runs.

Now if you are trying to load data from a file into a database, you need to investigate the LOAD DATA INFILE sql command.
 
Old 12-01-2003, 07:54 AM   #3
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
yer i'm trying to import the sql file into the nuke database.

then i would like to be able to view its contents..


I am alitte lost,

my sql sits in a folder called downloads

so you saying it would be like this

#>mysql -u root -p </home/user/downloads/nuke.sql

then i want to view it see if it worked



tommytomato

O i just tried what you said
and i get this
[root@www downloads]# mysql -u root -p </home/tommytomato/downloads/nuke.sql
Enter password:
ERROR 1046 at line 11: No Database Selected

Last edited by tommytomato; 12-01-2003 at 08:01 AM.
 
Old 12-01-2003, 12:03 PM   #4
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
OK, I think you are confusing a couple of things. If nuke.sql contains data to be loaded into the nuke database, the redirection I showed you isn't going to work. To load data that exists in a file, you need to use the LOAD DATA INFILE command (see the mySQL documentation for the fine details).

Now if nuke.sql contains sql commands that you need mysql to execute, then the redirection should work. You just need to add a little sql code to the top of the file. Since I'm assuming that the nuke database doesn't exist, and you want nuke.sql to create it, you need to create it as the first step. So the first couple of lines of nuke.sql should be:
create database nuke;
use nuke;
Other sql commands you want executed on nuke;


If the nuke database already exists, you only need to use the use nuke; to start nuke.sql.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting - help needed jonhewer Linux - Newbie 54 09-09-2005 02:58 PM
Darwin v 8.0.1 Shell help needed tuxfriend2 Other *NIX 1 07-31-2005 06:46 AM
shell resourses needed danharris Linux - Newbie 2 12-06-2004 03:41 AM
Shell scripting and background processes - help needed. trafalgar Programming 3 06-08-2003 09:15 AM
MySQL Help needed muhammade Linux - General 9 01-28-2003 07:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration