Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to manage mysql start and stop using service commands

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following mainly brings you how to manage mysql start and stop using service commands. I hope these contents can bring you practical use, which is also the main purpose of this article that my editor uses service commands to manage mysql start and stop. All right, don't talk too much nonsense, let's just read the following.

Start and stop the mysql service

# start / usr/local/mysql/bin/mysqld-- basedir=/usr/local/mysql-- datadir=/usr/local/mysql/data-- plugin-dir=/usr/local/mysql/lib/plugin-- log-error=/var/log/mysqld.log-- pid-file=/var/run/mysqld/mysqld.pid-- socket=/tmp/mysql.sock# stop kill `cat / usr/local/mysql/var/ mysqld.pid`

Starting and stopping like this requires remembering the path of mysql and the location where pid is saved, so it's troublesome.

Service system service management

The service command is used to manage system services, such as start, stop, restart, status, and so on. The service command itself is a shell script that can be easily invoked to complete the task, looking for the specified service script in the / etc/init.d/ directory.

Related orders include:

Chkconfig: used to view and set the running level of the service

Ntsysv: used to set up the self-startup of the service

Service runs the specified service (called the System V initial script), leaves only two environment variables LANG and TERM, and sets the current path to /. If a service script is to be managed by service, you need to at least support the start and stop commands and save the script in the / etc/init.d/ directory.

How to use service

# # Command format Usage: service

< option >

| |-- status-all | [service_name [command |-- full-restart]] # View the command line of the specified service using help service # # mysqld example $service mysqldUsage: mysqld {start | stop | restart | reload | status} [MySQL server options] # start, stop, restart the specified service service start | stop | restart## mysqld example restart, that is, execute stop before start command $service mysqld restartShutting down MySQL.. | [OK] Starting MySQL. [OK] # display the status of the specified service $service mysqld statusMySQL running (27390) [OK] # display the status of all services service-- status-all# View the list of system services And the run level chkconfig-list# setting of each service specifies whether to start chkconfig on automatically when the service is powered on | off# sets whether the service starts automatically when the service is powered on with a full-screen text interface # it must be started with root, space switch status, tab toggle button, mouse cursor up and down ntsysv

With the exception of mysqld, when we modify the host name, IP address and other information, we also need to restart the network frequently. At this time, you can call:

Service network status | restart

Managing mysqld Services with service

Now that we know the basics, we can start the modification, first of all, find the mysql.server file in your installation directory.

$locate mysql.server/usr/local/mysql/support-files/mysql.server

This file is initialized during installation, which is actually a script file that supports entering different parameters to perform different functions. We can look at its start function:

# execute different scripts according to the command entered, first determine whether it is startcase "$mode" in 'start') # Start daemon # Safeguard (relative paths, core dumps..) Cd $basedir echo $echo_n "Starting MySQL" # check to see if the bin/mysqld_safe command exists, and if not, simply report an error: no if test-x $bindir/mysqld_safe then # Give extra arguments to mysqld with the my.cnf file. This script # may be overwritten at next upgrade. # execute the mysqld_safe command directly, pass in parameters, and then create the pid file $bindir/mysqld_safe-- datadir= "$datadir"-- pid-file= "$mysqld_pid_file_path" $other_args > / dev/null & wait_for_pid created "$!"$mysqld_pid_file_path" Return_value=$? # Make lock for RedHat / SuSE if test-w "$lockdir" then touch "$lock_file_path" fi exit $return_value else log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)" fi;; 'stop')

Then copy it to the / tmp/init.d/ directory:

Cp / usr/local/mysql/support-files/mysql.server / tmp/init.d/mysqld

At this point, you can directly call service to start:

Service mysqld start

Some of the problems encountered

The above theory is very simple, but there are still some problems in the startup process. The easiest way to solve the problem is to check the log file by Google+. These two methods can locate and solve them very quickly.

Profile ignored

Look directly at the error message at startup:

$service mysqld startWarning: World-writable config file'/ etc/my.cnf' is ignoredStarting MySQL.Warning: World-writable config file'/ etc/my.cnf' is ignored

Looking directly at the cause of the error indicates that the globally writable configuration file is ignored. This error means that the configuration file can be modified by all users, so it is possible to be maliciously tampered with, so the configuration of this file will not be introduced and ignored.

The solution is to make the file readable and writable for users and user groups, while other users can only read and not write:

Chmod 664 / etc/my.cnf

PID file could not be created

Read the wrong message directly:

$service mysqld startStarting MySQL.The server quit without updating PID file (/ usr/var/mysql/var/mysqld.pid).

The reason for the error shows that you exited unexpectedly when you started MySQL because the PID file was not updated.

At this time, some people may not quite understand, it doesn't matter, let's just look at the error log:

2019-03-21 22:29:45 32896 [ERROR] / usr/local/mysql/bin/mysqld: Can't create/write to file'/ usr/var/mysql/var/mysqld.pid' (Errcode: 2-No such file or directory) 2019-03-21 22:29:45 32896 [ERROR] Can't start server: can't create PID file: No such file or directory

This log clearly states that the mysqld.pid file cannot be created, either because of permissions or because the path does not exist. Later, it is found that the path is written wrong, just change it to the correct path.

Settings for the error log path:

$vim my.cnf [mysqld] basedir = / usr/local/mysqldatadir = / usr/local/mysql/datapid-file = / usr/var/mysql/var/mysqld.pidlog-error = / user/local/mysql/log/mysql.err

The log instruction is discarded

After solving the above problem, we continue to execute and still find the same error message, but the log file is different:

$service mysqld startStarting MySQL.The server quit without updating PID file (/ usr/var/mysql/var/mysqld.pid). # Log file 2019-03-21 22:37:33 0 [ERROR] / usr/local/mysql/bin/mysqld: ambiguous option'--log=/usr/local/mysql/log/mysql.log' (log-bin, log_slave_updates) 2019-03-21 22:37:33 [ERROR] Aborting

Found that the log error message hint: vague option-log, this is not clear, Google can see the reason:-- log instruction has been abandoned for a long time, now use-- general-log instead. You can modify the my.cnf configuration file:

$vim my.cnf [mysqld] general-log = / user/local/mysql/log/mysql.log

Started successfully

After solving the above problems, we can finally start successfully. At this time, we can easily start / stop and reload the mysqld service:

$service mysqld startStarting MySQL. [OK]

For the above about how to use the service command to manage mysql start and stop, you do not find it very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report