MySQL Tutorial/MySQL Utilities/mysql — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 13:44, 26 мая 2010
Содержание
- 1 Continue even if errors in batch mode, you should use the --force command-line option
- 2 If anonymous (unnamed) user is allowed, you should be able to connect to that server by invoking mysql without any options:
- 3 If you are logging in on the same machine that MySQL is running on, you can omit the host.
- 4 If you need to specify connection parameters on the command line in batch mode
- 5 Logging In with mysql
- 6 Non-Interactive Commands
- 7 Remote Client Connection
- 8 Run the output through a pager
- 9 Supply your password on the command line after the -p option.
- 10 To escape some special characters in the file
- 11 To see a list of options provided by mysql, invoke it with the --help option:
- 12 Use scripts from the mysql prompt by using the source command or \. command
- 13 Using mysql in Batch Mode
- 14 You can catch the output in a file for further processing
- 15 You can select the database on the command line when you invoke mysql.
Continue even if errors in batch mode, you should use the --force command-line option
shell> mysql --force < batch-file
If anonymous (unnamed) user is allowed, you should be able to connect to that server by invoking mysql without any options:
shell> mysql
If you are logging in on the same machine that MySQL is running on, you can omit the host.
shell> mysql -u user -p
If you need to specify connection parameters on the command line in batch mode
shell> mysql -h host -u user -p < batch-file
Logging In with mysql
$ mysql -u <username> -p
Non-Interactive Commands
Just do a quick look up on a table without logging into the client, running the query then logging back out again.
You can instead just type one line using the " -e " flag.
c:\mysql\bin\mysql -u admin -p myDatabase -e "SELECT * FROM employee"
Remote Client Connection
If you have set the privileges to allow remote connections to a database, you can connect from a remote command line client by using the -h flag:
c:\mysql\bin\mysql -u <username> -p -h <host>
Run the output through a pager
shell> mysql < batch-file | more
Supply your password on the command line after the -p option.
You must do so with no intervening space
mysql> -pmypassword, not as -p mypassword
To escape some special characters in the file
shell> mysql -e "source batch-file"
To see a list of options provided by mysql, invoke it with the --help option:
shell> mysql --help
Use scripts from the mysql prompt by using the source command or \. command
mysql> source filename;
mysql> \. filename
mysql>
Using mysql in Batch Mode
Put the commands you want to run in a file.
shell> mysql < batch-file
You can catch the output in a file for further processing
shell> mysql < batch-file > mysql.out
You can select the database on the command line when you invoke mysql.
You must select database for use each time you begin a mysql session.
mysql>
shell> mysql -h host -u user -p yourDatabaseName
mysql>