How to automatically log on to the MYSQL command line tool

Source: Internet
Author: User

Method 1 for Automatic Logon of MYSQL command line tool. It is required that the mysql (command-line tool) terminal be often used to connect to the mysql db service in the linux environment.

The general syntax is as follows: mysql [options] db_name important option parameters include: -- database = db_name,-D db_name -- host = host_name, -h host_name -- password [= password],-p [password] -- port = port_num,-P port_num -- user = user_name,-u user_name The following is a call example: mysql-h10.6.28.90-uroot-Dtest-P3306-p

 

Every time you log on, you need to enter so many parameters that seriously affect productivity. Is there a simple way? 2. solution: In the working directory of the linux operating system, create a file under "/data/your user name" or "/home/your user name. my. cnf file. The configuration content is as follows:
 [client]user=rootport=3306host=10.6.28.90database=testdatabase=testpassword=MYsql3306

 

Finally, remove all other file attributes of. my. cnf and retain only the primary-readable attributes. See the following reference.
mark@PAY:~> cat .my.cnf[client]user=rootport=3306host=10.6.28.90database=testpassword=MYsql3306mark@PAY:~> ls -al .my.cnf-r-------- 1 mark users 78 2013-08-13 10:52 .my.cnf

 

3. The test result is now directly input mysql in the working directory to directly connect to the specified database of the specified database service, and there is no need to worry about entering login information such as passwords. 4. Working Principle
When the mysql command line is started, the configuration file Default options are read from the following files in the given order:/etc/my. cnf/etc/mysql/my. cnf/usr/local/mysql/etc/my. cnf ~ /. My. cnf this command can be used to run mysql; mysql/bin/my_print_defaults

 

View. If the preceding directory contains files, the configuration of the last file overwrites the configuration of the previous file. Therefore, the priority level is the lowest ~ The configuration of the/. my. cnf file is used and the logon is successful.

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.