Learning Mysql


Running the Monitor in Batch Mode | 101



Download 4.24 Mb.
View original pdf
Page97/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   93   94   95   96   97   98   99   100   ...   366
Learning MySQL
Running the Monitor in Batch Mode | 101


$ mysql --user=root --password=the_mysql_root_password < count_users.sql
count(*)
4
Loading the Sample Databases
To get a working sample database that you can play with, start by visiting the book’s website and downloading the music database file music.sql from the sample databases section.
To load the file into your server, you need to use the
SOURCE
command and specify where
MySQL can find the music.sql file. For example, this might be
/music.sql
or

/Desktop/music.sql
on a Linux or Mac OS X system, or C:\Documents and Settings
\my_windows_login_name\Desktop\music.sql on a Windows system.
Once you run the
SOURCE
command, you should see some reassuring messages flash by:
mysql> SOURCE path_to_music.sql_file;
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.01 sec)
Query OK, 1 row affected (0.00 sec)
You can now see if the database is thereby using the SHOW DATABASES
command:
mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| music |
| mysql |
| test |
+----------+
3 rows inset sec)
mysql>
We’ll see how to use this database in future chapters.
Repeat this process for the two additional sample database files, flight.sql and univer-
sity.sql, that are available from the book’s website. Finally, you can leave the MySQL
monitor by typing
quit
:
mysql> quit
MySQL Monitor Program Options
The monitor program can take several parameters the ones you’ll need most frequently are:
102 | Chapter 3:
Using the MySQL Monitor

host
The host the server is running on you can leave this out if the server is running on the same host as the client (
localhost
).
user
The username to use when connecting to the MySQL server. This bears no relation to the username the server is running under, or to your Linux or Mac OS X username. If you don’t provide a username with this option, the monitor uses a default value this default username is your machine account name on a Linux or Mac OS
X system, and
ODBC
on a Windows system.
password
The password of this user. If you don’t provide the password parameter, no password is supplied to the server. This is fine if there is no password stored for that user, but if the user does have a password, the connection will fail mysql --user=the_username
ERROR 1045 (28000): Access denied for user 'the_username'@'localhost'
(using password NO)
If you include the password option but don’t specify a password, the client will prompt you fora password after you press the Enter key. If the user has no password, pressing the Enter key will work otherwise, the connection will fail again mysql --user=the_username --password
Enter password:
ERROR 1045 (28000): Access denied for user 'the_username'@'localhost'
(using password NO)
If you provide an incorrect password, or you don’t have permission to access a specified database, MySQL will note this in the error message mysql --user=the_username --password=wrong_password
Enter password:
ERROR 1045 (28000): Access denied for user 'the_username'@'localhost'
(using password YES)
If you specify the correct password at the Enter password:
prompt, or if you specify the correct password on the command line when starting the monitor, the connection will succeed mysql --user=the_username --password=the_password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 169 to server version Type 'help' or 'h' for help. Type 'c' to clear the buffer.
mysql>
Some users prefer not to specify the password on the command line because suppressing the password guarantees the password won’t be displayed in the operating system process table or command history. Under all operating systems we’ve tested, the password is hidden and can’t be seen using operating system utilities to

Download 4.24 Mb.

Share with your friends:
1   ...   93   94   95   96   97   98   99   100   ...   366




The database is protected by copyright ©ininet.org 2024
send message

    Main page