Start and stop of Mysql server (ii)

  • 2020-05-06 11:44:43
  • OfStack

Stop server  
To manually start the server, use MySQLadmin:  

        %mysqladmin   shutdown  

        to automatically stop the server, you don't have to do anything special. BSD systems typically stop service by sending an TERM signal to processes, which either respond to it correctly or are killed rudely. mysqld replies with termination when it receives this signal. For System   V style systems that start the server with mysql.server, stopping the process will call the script with an stop parameter, telling the server to terminate, assuming you have mysql.server installed, of course.  

4. If you cannot connect to the server, how can you regain control of the server
In some cases, you may manually restart the server because you cannot connect to it. Of course, this is a bit of a contradiction. Because you normally turn off the server manually by connecting to it, how does this happen?  

First, the MySQL   root password can already be set to a value that you do not know. This can happen when you change the password, for example, if you accidentally type an invisible control character while entering a new password. You may also forget the password.  

Second, connections to localhost are usually made through an Unix domain socket file, typically /tmp/ mysql.sock. If the socket file is deleted, the local client cannot connect. This may happen when your system runs an cron task that deletes /tmp under temporary files.  

If you can't connect because you lost the socket file, you can simply recreate it by restarting the server. Because the server recreates it at startup. The trick here is that you can't make a connection with a socket because it's gone, you have to make an TCP/IP connection, for example, if the server host is pit.snake.net, you can make a connection like this:  

        %mysqladmin   -p   -u   root   -h   pit.snake.net   shutdown  

        if the socket file is a cron task to delete, questions will be repeated, unless you modify cron task or use one or use a different socket file, you can use the global options file specifies a different socket, for example, if the data directory is/usr/local/var, you can use to add the following line to/etc/my cnf, socket file will be moved to the there:  

        [mysqld]  
        socket=/usr/local/var/mysql.sock  

        [client]  
        socket=/usr/local/var/mysql.sock  
        specifies a pathname for both the server and the client so that they all use the same socket file. If you only set the path for the server, the client will still expect to execute the socket in the original location, restart the server after the change, and let it create the socket in the new location.  

        if you cannot connect because you forgot the root password or have set it to a different value than you think, you need to regain control of the server. You can set the password again:  

       

Interrupt server  

        if you log on to the server host as root, you can terminate the server with the kill command. You can use the ps command or find the ID of the server process by looking for the server's PID file (usually in the data directory).  

        is best to first try a normal kill that sends an TERM signal to the server to see if it will terminate the reply as normal. In this way, the tables and logs are properly cleared. If the server blocks and does not respond to a normal termination signal, you can force it to terminate with kill  -9. This is a last resort, because there may be uncleared changes, and you risk leaving the table in an inconsistent state.  

If you terminate a server with kill  -9, be sure to check your table with myisamchk and isamchk before starting the server.    
Restart the server with the -- skip-grant-table option.  
This tells the server not to authenticate the connection with an authorization table, which allows you to connect with root without requiring a password. After you have connected, change the root password.    
        tells the server to start  
again using the authorization table with mysqladmin   flush-privileges If your version of mysqladmin does not recognize Flash-privileges, try reload.  

        5. Run multiple servers  

Most         runs a single MySQL server on a given machine, but in many cases it is useful to run multiple servers:  

You may want to test a new version of a server, but keep the production server you are running on. In this case, you run different server code.    
The         operating system generally limits the number of open file handles per process. If your system has a hard time raising this limit, running multiple servers is one way to get around it. In this case, you might run multiple instances of the unified server.    
        ISP often provides its customers with their own MySQL installations, and it is necessary to involve a separate server. In this case, you may run multiple instances of the same version or different versions if different customers want different versions of MySQL.    
Naturally, running multiple servers is more complicated than running just one. If you install multiple versions, you can't install everything in the same place. When the server runs, certain parameters must or are likely to be unique to each server, including where the server is installed, the pathname of its data directory, the TCP/IP port and UNIX domain socket pathname, and the UNIX account used to run the server (if you do not run all the servers under the same account). If you decide to run multiple servers, be sure to pay attention to the parameters you use that you don't.


Related articles: