MySQL database startup & shutdown

MySQL database startup & shutdown

The MySQL database server usually refers to mysqld, and the command line mysql is the mysql client program. These two concepts are often confused. Usually, starting the mysql server is to start the mysqld process. After mysqld is started, you can connect to the mysql server through mysql. This article mainly describes several ways to start the mysql server and how to shut down the mysql server.

mysqld_safe is a shell script

mysql is the service

Current mysql server running environment
[root@localhost ~]# cat /etc/issue

CentOS release 6.8 (Final)
Kernel \r on an \m
View the default options when mysqld starts

You can view the configuration file information through the following command, and check that mysql is started with the correct parameter file, and determine whether there are other parameter files affected.

[root@localhost ~]# mysqld --print-defaults
Does the current process have mysql
[root@localhost ~]# ps -ef|grep mysql
[root@localhost ~]# ps -ef|grep mysql|grep -v grep
View the current my.cnf configuration file
[root@localhost ~]# grep -v ^# /etc/my.cnf|head -n 7
[client]
port            = 3306
socket          = /tmp/mysql.sock

[mysqld]

Startup mode, mysqld mysql_safe mysql.server


1. Start with service: service mysqld start

2. Use the mysqld script to start: /etc/inint.d/mysqld start (this method is not recommended, this is to start the mysqld process directly, regardless of whether it has been started before)

3. Use mysqld_safe to start: go to the bin corresponding to the mysql installation purpose, and execute the command ./mysqld_safe –user=mysql & (recommended)

[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql &

set mysql password

[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -uroot password 123456

Clear history command

history   -c

Add password 123 to mysql user root [note that the password cannot be written as "123"] [use set to change the password after entering mysql]

[root@localhost ~]# /usr/local/mysql/bin/mysql -u root -p123456

ysql>show databases;  #查看库
mysql>use test;       #使用表
mysql>show tables;    #查看表
mysql>\s              #查看字符集是否改为utf8

How to set up mysql to start automatically

[root@localhost ~]#  echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >>/etc/rc.local   

Note: The rc.local file is the user-defined startup file
rc.local link file, which refers to /etc/rc.d/rc.local. It is a script that is executed at the end after the system initialization and services are started. Some simple scripts can be placed in it https://www.zhihu.com/question/20126189

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324723815&siteId=291194637