The configuration information of the mysql server and client is in the my. cnf file ----- & #39;/va

Source: Internet
Author: User
Changed the mysql data file directory to homemysql, the default data file directory to varlibmysql during installation, the configuration file to etcmy. cnf, and change datadirhomemysql in the etcinit. dmysql file. We need to know that the etcmy. cnf configuration file contains the configuration for the mysql server and client. Perform the following operations:

The data file directory of mysql is/home/mysql. The default data file directory is/var/lib/mysql and the configuration file is/etc/my. cnf, change/etc/init. d/datadir =/home/mysql In the mysql file. We need to know that the/etc/my. cnf configuration file contains the configuration for the mysql server and client. Perform the following operations:

The data file directory of mysql is/home/mysql. The default data file directory is/var/lib/mysql and the configuration file is/etc/my. cnf, change/etc/init. d/datadir =/home/mysql In the mysql file.

We need to know that the/etc/my. cnf configuration file contains the configuration for the mysql server and client.

Then, rename my. cnf is my. cnf-bak, change/etc/init. d/datadir In the mysql file is the default path datadir =, and then start the mysql server/usr/bin/mysqld_safe -- defaults-extra-file =/etc/my. cnf-bak, mysql Server started successfully, view mysqld, mysql process information ps-ef | grep-I mysql *, display mysql datadir as/home/mysql, sock is/home/mysql. sock, other information is also displayed normally, and then try to log on to the mysql database, then an error is reported indicating/var/lib/mysql. sock does not exist. Why? Because my. the cnf configuration file does not exist. If the mysql client does not find the configuration file, it reads the default path specified during rpm package compilation during mysql installation, while/var/lib/mysql. sock does not exist, so an error is returned. That is to say, the Information read by the mysql client from the default parameter is inconsistent with the modified datadir =/home/mysql information. Therefore, you cannot log on to the mysql server.


1) in/etc/init. d/mysql, datadir =/home/mysql sets the data file directory in the mysql Startup File.

2) view/etc/, basedir, datadir ,~. Whether the my. cnf configuration file exists under/my. cnf
3) CHANGE/etc/my. cnf to/etc/my. cnf-bak. mysql reads the default parameters set during compilation at startup.
4) the mysql service can be started normally at this time, because the directory of the specified data file is displayed in/etc/init. d/mysql (which seems to be in conflict with the third? In fact, the default parameter 3 is here)
# Service mysql start
# Mysqladmin-uroot-p variables | grep-I basedir
# Mysqladmin-uroot-p variables | grep-I datadir
5) Modify datadir in the/etc/init. d/mysql file and comment out the specified datadir =/home/mysql
6) try to close the mysql database
# Service mysql stop
# MySQL server PID file cocould not be found! [FAILED]
This is because the datadir =/home/mysql of mysql is modified. mysql reads the PID file according to the default path/var/lib/mysql compiled in the mysql rpm package, the/var/lib/mysql file does not have a PID, so the prompt is displayed.
7) You can use mysqladmin-uroot-p shutdown to shut down the mysql process normally.
8) because of/etc/my. cnf, basedir, datadir ,~ /. My. cnf does not exist and mysql cannot be started.
You can view the parameters of mysqld_safe through/usr/bin/mysqld_safe -- help, and then use
#/Usr/bin/mysqld_safe -- defaults-extra-file =/etc/my. cnf-bak
Specify the mysql STARTUP script and start the mysqld process. At this time, the mysqld_safe process occupies the terminal (in the current terminal, other operations are not allowed), use Ctrl + Z to stop the mysqld process (sleep process), and then use bg (fg to put the background job to the foreground) set the mysqld_safe process to the background process (the process will be restored from sleep to running, and used ).


###########
9) try to connect to the mysql database and view mysql information.
# Mysqladmin-uroot-p variables | grep-I datadir
Mysqladmin: connect to server at 'localhost' failed
Error: 'Can't connect to local MySQL server through socke'/var/lib/mysql. sock '(2 )'
Check that mysqld is running and that the socket: '/var/lib/mysql. sock' exists!
The error message "/var/lib/mysql. sock" fails to connect to the mysql server.
Try to connect to the mysql database,
# Mysql-uroot-p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql. sock' (2)
###########
View mysql process information:
[Root @ localhost ~] # Ps-ef | grep-I mysql *
Root 18835 5614 0 00:00:00 pts/1/bin/sh/usr/bin/mysqld_safe -- defaults-extra-file =/etc/my. cnf-bak
Mysql 19133 18835 0 00:00:00 pts/1/usr/sbin/mysqld -- defaults-extra-file =/etc/my. cnf-bak -- basedir =/usr -- datadir =/home/mysql -- plugin-dir =/usr/lib/mysql/plugin -- user = mysql -- log-error =/home/ mysql/localhost. localdomain. err -- pid-file =/home/mysql/localhost. localdomain. pid -- socket =/home/mysql. sock -- Ports = 3306
At this time, we will find that the socket path displayed in the mysql process information is my. the path/home/mysql specified in cnf-bak. sock, but cannot connect to/var/lib/mysql through the default socket path. sock connection.
############
This is because/etc/my. cnf, basedir/my. cnf, datadir/my. cnf ,~ /. My. the cnf file does not exist. when starting the mysql service, use/usr/bin/mysqld_safe -- defaults-extra-file =/etc/my. cnf-bad specifies the configuration file read by mysql_server at startup, so that the mysql server process is successfully started. When the mysql_client client uses the mysqladmin client tool or mysql tries to log on to the mysql server through the client, the mysql client will look for my. cnf configuration file (my. cnf contains the mysql server [mysqld] and client [client] settings), because my. the cnf configuration file cannot read user settings. The mysql client uses the default directory set during mysql installation, but the default data file directory/var/lib/mysql does not have mysql. sock, so the error message "/var/lib/mysql" is not found. sock.


Configuration information classification in my. cnf:

Mysqld_safe/mysqld/mysqld_multi is configured on the server.


Client configurations such as mysqldump/mysql/client/mysqladmin

[Client] the user tells the client tool mysql to connect to the port and socket file path used by the database server.

[Mysql] is used to set the display information of the client tool, as shown in my. cnf.

[Mysql]

# Prompt = "(\ u: hostname: \ D) [\ d]>"

When mysql-uroot-p is used to connect to the mysql server, the following information is displayed:

(Root: hostname: Thu Feb 9 16:32:26 2012) [(none)]>

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.