Run the MySQL file directly on the Linux Command Line

Source: Internet
Author: User
Note that this is in Linuxbash and cannot be used in Windows .. However, you can try to write a bat batch file to achieve the same effect! To run a mysql file, such

Note that in Linux bash, this is certainly not supported in Windows .. However, you can try to write a bat batch file to achieve the same effect! To run a mysql file, such

Note that in Linux bash, this is certainly not supported in Windows .. However, you can try to write a bat batch file to achieve the same effect!

To run the mysql file,If you have logged on to mysql, you can directly run: source filename. SQL In the mysql command line., Very simple!

But isn't that too troublesome?

Okay .. Run it directly on the command line .. You can enter:Mysql-u USERNAME-pPASSWORD DATABASENAME <filename. SQL

Here, USERNAME is the USERNAME you want to log on to, PASSWORD is the PASSWORD, and DATABASENAME is the name of the database you want to use, which is short of oil !! La !!!~

The input is too long. Right !!! Trouble!

Change it. Write an alias and write it to The. bashrc file !!! But in order not to conflict with the original, the alias is now taken as SQL ..

Vim ~ /. Bashrc

Add this line at the end of SQL = "\ mysql-u username-pPassword datebasename <" # note that there is a "\" behind mysql

# Do not reference an alias that already exists. You need to escape it. Of course you have not defined any other alias. It doesn't matter!

This is near perfect, isn't it?

But this is better for beginners!

Alias SQL = "\ mysql-u USERNAME-pPASSWORD -- auto-rehash -- line-numbers -- show-warnings DATABASENAME <"

Then run the script:Source ~ /. Bashrc

OK. Now you can run the script file directly. For example, if you have written a test. SQL file, you can run it like this:

SQL test. SQL

This is more convenient .. At least I think so .. In addition, the input is a line in the mysql command line. I prefer to write a file !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.