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 start and connect MySQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

What the editor wants to share with you this time is how to start and connect MySQL. The article is rich in content. Interested friends can learn about it. I hope you can get something after reading this article.

The operation of MySQL consists of two parts, one is the server program mysqld, and the other is the client program mysql. The mysql client can connect to mysqld only if it is started. There are four ways to start mysqld, and there are also four ways to connect mysql.

The startup mode of mysqld, 1:mysqld

Mysqld is an executable command and a server-side program, and starting this program is equivalent to starting a MySQL server-side process. But this command is not commonly used, the mysqld_safe command is commonly used.

Command format: mysqld [OPTIONS] such as: mysqld-- defaults-file=/etc/my.cnf View help: mysqld-- verbose-- help mode 2:mysqld_safe

Mysqld_safe is a startup script that indirectly references mysqld. When you start the mysqld_safe script, when you start the MySQL server process, a daemon is started to monitor the mysqld, such as restart a mysqld service immediately after the mysqld service dies.

In addition, the mysqld_safe startup mode will also output the error log and other diagnostic information of the running process to a certain file, which is convenient for us to troubleshoot and solve the problem. This startup mode is the most commonly used.

Command format: mysqld_safe [OPTIONS] & such as: mysqld_safe-- defaults-file=/etc/my.cnf & View help: mysqld_safe-- help mode 3:mysqld_multi

If you need to run multiple MySQL instances on a single host, you can use mysqld_multi to manage different mysqld services, which is helpful for MySQL clusters.

Command format: mysqld_multi [OPTIONS] {start | reload | stop | report} [GNR,GNR,GNR...] Check out help: mysqld_multi-help 4:mysql.server

Mysql.server is also a startup script that calls mysqld_safe indirectly and starts the server program by specifying the start parameter after the call to mysql.server. This startup method is generally generated through the MySQL installed by the RPM package.

The mysql.server file is actually a linked file, and its actual file is.. / support-files/mysql.server

Command format: mysql.server start | restart | stop | connection method of statusmysql 1:TCP/IP socket

It can be used in both Unix-like and Windows-like operating systems. TCP/IP socket is a network protocol, which can be connected by listening to a port when the MySQL server is started and indicating the host IP+ port of the MySQL server when the client starts the connection.

This kind of communication, MySQL server and client can be deployed on different hosts, and it is also the most commonly used connection mode.

Mysql-h host IP-P port-u user-p such as: mysql-h227.0.0.1-P3306-uroot-p

Mode 2:Unix socket

Unix socket is not a network protocol and can only be used on the same host as the MySQL server and the client on the same host.

If we specify the hostname localhost when we start the client program, or if we specify the startup parameter of-protocol=socket, then the server program and the client program can communicate through the Unix domain socket file.

The path to the Unix domain socket file that the MySQL server program listens to by default is / tmp/mysql.sock, and the client program also connects to this Unix domain socket file by default.

1. Mysql-uroot-p / / defaults to localhost2 through socket communication. Mysql-hlocalhost-uroot-p3. Mysql-S socket file path-uroot-p such as: mysql-S / var/run/mysqld/mysqld.sock-uroot-p

View the socket file location: show variables like 'socket'

Method 3: naming pipes

It can only be used under a Windows-like operating system, and can only be used on the same host as the MySQL server and client.

You need to add the-- enable-named-pipe parameter to the command to start the server program, and then add the-- pipe or-- protocol=pipe parameter to the command to start the client program.

-enable-named-pipe=on/off; mode 4: shared memory

It can only be used under a Windows-like operating system, and can only be used on the same host as the MySQL server and client.

You need to add the-- shared-memory parameter to the command to start the server program. After successfully starting the server, the shared memory becomes the default connection mode for the local client program, but we can also add the-- protocol=memory parameter to the command to start the client program to explicitly specify the use of shared memory for communication.

-after reading this article on how to launch and connect to MySQL, shared-memory=on/off; can share it with more people if he thinks it is well written.

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