MySQL Utilities connection MySQL server tutorial

Source: Internet
Author: User
Tags socket string format versions port number

The

connection parameter

connects to a server and must specify the connection parameters, such as user name, host name, password, port number, socket. The MySQL utilities provides three ways to provide these parameters, all of which need to be specified through the command line.

    use. mylogin.cnf files (encrypted, invisible). For example: <login-path>[:<port>][:<socket>]
    Use a configuration file (unencrypted, invisible). Applies only to 1.5.0 and above versions. such as: <configuration-file-path>[:<section>]
    specified on the command line (unencrypted, visible). such as: <user>[:<passwd>]@
uses login-paths (. MYLOGIN.CNF)

Using this method to connect to a database is best. Not only is the file encrypted, but any records that are executed do not expose the connection information. Therefore, the log of user name, password, port and other information is not visible. This is the preferred method of connecting to a database using the MySQL utilities tool.

Note: MySQL Utilities1.2.1 and later versions support the Login-paths method. The string format of the

Connection is: login-path-name[:p Ort][:socket]. Where port and socket are optional parameters. If specified, overrides defined in Login-path.

When using login-paths, there is no default value except for the POSIX system, when the socket is specified. In this case, the host option default value is localhost. This means that, combined with Login-path, the specified value has two optional values, port, and socket selection, at least one user name, one hostname, one port, or one socket will need to be specified. The

uses the Mysql_config_editor tool to add the following connection information:

The code is as follows Copy Code
# cd/usr/local/mysql5.6/
#./bin/mysql_config_editor Set--login-path=instance_3366--host=localhost--user=root--port=3366--password
Enter Password:


A hidden encrypted file will be created in the home directory. Mylogin.cnf.

View. MYLOGIN.CNF Content:

The code is as follows Copy Code
#./bin/mysql_config_editor Print--login-path=instance_3366
[instance_3366]
user = root
Password = * * *
host = localhost
Port = 3366


Once you have configured the. mylogin.cnf file, you only need to specify the server segments in the. mylogin.cnf file to connect. For example, the "instance_3366" service segment was created in the previous examples. Therefore, we can use –server=instance_3366. The login path for the specified section as shown below:
# Mysqlserverinfo--server=instance_3366--format=vertical

You can also customize it as follows:

The code is as follows Copy Code
# Mysqlserverinfo--server=root: @localhost: 3366:/tmp/mysql3366.sock--format=vertical
Warning:using a password on the command line interface can is insecure.
# Source on localhost: connected.
1. Row *************************
server:localhost:3366
Config_file:/USR/LOCAL/MYSQL5.6/MY.CNF,/MY.CNF
binary_log:master-bin.000003
binary_log_pos:151
Relay_log:
Relay_log_pos:
Version:5.6.16-log
DataDir:/usr/local/mysql5.6/data/
Basedir:/usr/local/mysql5.6
Plugin_dir:/usr/local/mysql5.6/lib/plugin/
General_log:off
General_log_file:
General_log_file_size:
Log_error:/usr/local/mysql5.6/data/localhost.err
log_error_file_size:2238 bytes
Slow_query_log:off
Slow_query_log_file:
Slow_query_log_file_size:
1 row.
#...done.


Using configuration Files


MySQL utilities can also accept configuration paths and segments for server-attached data. This allows you to store the connection information for one or more parts. Saving data in a configuration file is more secure than specifying it on the command line, but the file is a text file that can be read by anyone who has access to the file.

The code is as follows Copy Code
The MY.CNF connection segment looks like this:
# Vim MY.CNF
[Client]
Port = 3366
Socket =/tmp/mysql3366.sock
User=root



To use a configuration file:

The code is as follows Copy Code
# Mysqlserverinfo--server=/usr/local/mysql5.6/my.cnf[client]--format=vertical
# Source on localhost: connected.
1. Row *************************
server:localhost:3366
Config_file:/USR/LOCAL/MYSQL5.6/MY.CNF,/MY.CNF
binary_log:master-bin.000003
binary_log_pos:151
Relay_log:
Relay_log_pos:
Version:5.6.16-log
DataDir:/usr/local/mysql5.6/data/
Basedir:/usr/local/mysql5.6
Plugin_dir:/usr/local/mysql5.6/lib/plugin/
General_log:off
General_log_file:
General_log_file_size:
Log_error:/usr/local/mysql5.6/data/localhost.err
log_error_file_size:2238 bytes
Slow_query_log:off
Slow_query_log_file:
Slow_query_log_file_size:
1 row.
#...done.

The


use the command line

To specify connection server information through command-line arguments is the least secure, and the data is visible on the command line and in the log file.

In this way, the order of the specified parameters is: <user>[:<passwd>]@
instance is shown above.
Define in the Python library

If you use the MySQL utilities library file to create your own tools, you will encounter a variety of connection styles. The

Optional methods are:

    a python dictionary with connection parameters.
    A string containing the connection parameters.
     Specify a server instance. The

Dictionary is formatted as follows:

The code is as follows Copy Code
# Set Connection Values
Dest_values = {
"User": "Root",
"passwd": "Secret",
"Host": "LocalHost",
"Port": 3308,
"Unix_socket": None,
}

The string format is:

The code is as follows Copy Code
<user>[:<passwd>]@

The bracket is an optional parameter.

The connection string is parsed by using the Options.parse_connection function.

You can also specify an instance of the server class, in which case the new class will replicate the connection information.

Related Article

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.