By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,276 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,276 IT Pros & Developers. It's quick & easy.

how do I create a database on linux machine running mysql?

P: n/a
MLH
I have an sql script file that is supposed to create
a set of database tables for me. Supposedly I type
the following on my linux box and its all supposed
to work...

mysql (ENTER)
\. mysql_dump.sql.txt

When I type myslq <ENTER> I get a command prompt
that looks like this...

mysql>

But I don't know how to change directories from that
command prompt to the directory where mysql_dump.sql.txt
is located. Can someone tell me how to change dirs at
the mysql> prompt?
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
MLH wrote:
I have an sql script file that is supposed to create
a set of database tables for me. Supposedly I type
the following on my linux box and its all supposed
to work...

mysql (ENTER)
\. mysql_dump.sql.txt

When I type myslq <ENTER> I get a command prompt
that looks like this...

mysql>

But I don't know how to change directories from that
command prompt to the directory where mysql_dump.sql.txt
is located. Can someone tell me how to change dirs at
the mysql> prompt?


From the command line to load a mysql dump file do this:

mysql -u [username] -p [database_name] < [filename]
eg
mysql -u someuser -p somedb < mysql_dump.sql.txt

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jul 23 '05 #2

P: n/a
MLH,
There is a good book called MySQL written by Paul DuBois, it has
tutorials and stuff. It seems like you are new to databases from the
question you asked. I highly recommend you getting the book and learn
this fun stuff if you have the inclination to absorb this technology.

usaims

Jul 23 '05 #3

P: n/a
usaims wrote:
There is a good book called MySQL written by Paul DuBois, it has
tutorials and stuff.


There's also a MySQL tutorial online at:
http://dev.mysql.com/doc/mysql/en/tutorial.html

With regards to loading data from the script, there are several choices:

One option is to cd to the directory before you run the mysql tool:
$ cd directory/containing/script
$ mysql
mysql> source mysql_dump.sql.txt

Another option is to use the path to the dump file:
$ mysql
mysql> source directory/containing/script/mysql_dump.sql.txt

Another option, as Chris Hope pointed out, is to run the script directly
from the command line:
mysql databasename < directory/containing/script/mysql_dump.sql.txt

(you also might need to specify "-u username" and "-p", if the database
is configured to require a non-anonymous login and password)

Regards,
Bill K.
Jul 23 '05 #4

P: n/a
Bill Karwin wrote:
usaims wrote:
There is a good book called MySQL written by Paul DuBois, it has
tutorials and stuff.


There's also a MySQL tutorial online at:
http://dev.mysql.com/doc/mysql/en/tutorial.html

With regards to loading data from the script, there are several
choices:

One option is to cd to the directory before you run the mysql tool:
$ cd directory/containing/script
$ mysql
mysql> source mysql_dump.sql.txt

Another option is to use the path to the dump file:
$ mysql
mysql> source directory/containing/script/mysql_dump.sql.txt

Another option, as Chris Hope pointed out, is to run the script
directly from the command line:
mysql databasename < directory/containing/script/mysql_dump.sql.txt

(you also might need to specify "-u username" and "-p", if the
database is configured to require a non-anonymous login and password)


I hadn't seen that "source" one from within the mysql command prompt
before. That's really cool. Thanks Bill.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jul 23 '05 #5

P: n/a
MLH
Thank-you for suggesting this syntax...
mysql databasename < directory/containing/script/mysql_dump.sql.txt
I tried it. I got an error msg. Here is the error...
ERROR 1044: Access denied for user: '@localhost' to database
'mydatabase'

I was not logged in as root at the time of running the command.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<snip>

Another option, as Chris Hope pointed out, is to run the script directly
from the command line:
mysql databasename < directory/containing/script/mysql_dump.sql.txt <snip>Regards,
Bill K.


Jul 23 '05 #6

P: n/a
MLH
I tried cd'ing to the directory containing mysql_dump.sql.txt,
running mysql <ENTER> and finally source mysql_dump.sql.txt.
A bunch of error messages saying
ERROR 1046: No Database Selected
filled up the screen.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x

One option is to cd to the directory before you run the mysql tool:
$ cd directory/containing/script
$ mysql
mysql> source mysql_dump.sql.txt

Another option is to use the path to the dump file:
$ mysql
mysql> source directory/containing/script/mysql_dump.sql.txt

Another option, as Chris Hope pointed out, is to run the script
directly from the command line:
mysql databasename < directory/containing/script/mysql_dump.sql.txt

(you also might need to specify "-u username" and "-p", if the
database is configured to require a non-anonymous login and password)


I hadn't seen that "source" one from within the mysql command prompt
before. That's really cool. Thanks Bill.


Jul 23 '05 #7

P: n/a
MLH
I tried the following syntax
mysql -u mlh -p mydatabase < mysql_dump.sql.txt
and received the following error msg...

ERROR 1045: Access denied for user: 'mlh@localhost' (Using Password:
YES)

The mlh user is my non-root linux userID. The recommended syntax
shown below indicates 'someuser' and mlh is what I used. Also, it
indicates 'somedb'. I used 'mydatabase' as the name, since I am
doing this for test purposes now. Since I don't have a database yet
(running this script is supposed to create one) I assume the name I
use in place of somedb will be the name of the database that's created
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<snip>

From the command line to load a mysql dump file do this:

mysql -u [username] -p [database_name] < [filename]
eg
mysql -u someuser -p somedb < mysql_dump.sql.txt


Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.