Home Database Mysql Tutorial Summary of problems that occur when the server remotely connects to mysql

Summary of problems that occur when the server remotely connects to mysql

Apr 19, 2019 pm 05:13 PM
mysql Server connection

This article summarizes the problems that arise when the server remotely connects to mysql. I would like to share it with you and learn together.

1. Solve the problem of remote connection failure under centos.

1. Check whether the firewall is closed under centos:
Through the process: ps -aux |grep firewalld
ps -ef |grep firewalld
Through the service: pgrep firewalld
systemctl status firewalld
Turn off the firewall: systemctl stop firewalld
service iptables off
2. The remote connection uses the sshd service, which is the ssh protocol. The port number is 22.
Check whether the sshd service is turned on:
Through the process: ps -aux |grep sshd
Through the service: pgrep sshd
Start the service: systemctl start sshd
Add the sshd service to the boot: chkconfig sshd on

3. Check the IP address.
 ifconfig
Under Windows, in the cmd window, ping the above IP address to see if the ping can succeed.

What should I do if I report an error?

Can’t connect to the database? The following problem occurs?
 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock? ? ?
what to do?
First check /etc/rc.d/init.d/mysqld status to see if mysql has been started.
If it is a permission problem, change the permissions first #chown -R mysql:mysql /var/lib/mysql

 [root@localhost ~]# /etc/init.d/mysqld start
Start MySQL: [OK]
 [root@localhost ~]# mysql -uroot -p

 10038? (Remote without authorization)
 10060? (Join the security group)

Related tutorials: mysql video tutorial
2. Database operations:
1. Start mysql.
systemctl start mariadb
2. The first step is to set the password. You will be prompted to enter the password first
mysql_secure_installation
3. Create a normal user:
create user zhangsan@localhost identified by 'root';
mysql -u root -p
update user set host='%' where host='127.0.0.1';
flush privileges;
4. Authorize root user to log in remotely:
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Flush privileges;
update user set user='root' where host='localhost';

Related tutorials: mysql video tutorial
3. Solution to mysql remote connection failure:
1. Firewall:
Set the firewall and it will not start at boot:
chkconfig firewalld off
Turn off the firewall:
Systemctl disable firewalld
Systemctl stop firewalld
Or kill the firewall process.
Check whether the firewall process exists: pgrep firewalld,
Then kill the process: kill pid
Or pkill firewalld
2. No remote permissions
Grant remote login permissions
grant all privileges on *.* to 'root'@'%' identified by '123456';
Flush privileges;

3. Start the sshd service: systemctl start sshd
Add the sshd service to boot: chkconfig sshd on

4. Access projects under Linux in Windows
Start the Apache service in Linux, that is, httpd service systemctl start httpd or: service httpd start
Access Linux from the browser under Windows Items under: Enter the IP address in the browser address bar: (You can check your own IP address through ifconfig) For example, 192.168.0.1

5. How to configure virtual domain name under Windows:
Configure local hosts file .
Location: C:\Windows\System32\drivers\etc\hosts
Just add the corresponding virtual host name.
 192.168.226.129 linux.cc


CRUD for mysql;
Add:
INSERT INTO `user` (`id`, `username`, `passwd`, `sex`) VALUES ('1', 'zhangsan', '12345', '')
Update:
UPDATE `user` SET `sex`='女' WHERE (`id`='2')
Delete:
DELETE FROM `user` WHERE (`id`='2')
Query:
 SELECT * FROM `user`;

6. Virtual Host
 
 ServerAdmin webmaster @dummy-host.example.com
 DocumentRoot /www/docs/dummy-host.example.com
 ServerName dummy-host.example.com
 ErrorLog logs/dummy-host.example.com-error_log
 CustomLog logs/dummy-host.example.com-access_log common
 


7. Set startup: switch the default graphical interface to the command line mode
  Modify to Command mode multi-user.target:
 [root@localhost ~]# systemctl set-default multi-user.target
 rm '/etc/systemd/system/default.target'
 ln -s ' /usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'
 [root@localhost ~]# systemctl get-default
 Get: multi-user. target: achieve the effect.
Switch to: graphical mode: systemctl set-default graphical.target

8. Configuration file description
A: httpd.conf The main configuration file of Apache.
B: php.ini PHP’s main configuration file
D: httpd-vhost.conf When configuring the virtual host, the changed file
E: my.cnf Mysql’s main configuration file under Linux

Note: The main configuration file mysql under Windows my.ini

Related tutorials: PHP video tutorial

The above is the detailed content of Summary of problems that occur when the server remotely connects to mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use PHP to develop a Q&A community platform Detailed explanation of PHP interactive community monetization model How to use PHP to develop a Q&A community platform Detailed explanation of PHP interactive community monetization model Jul 23, 2025 pm 07:21 PM

1. The first choice for the Laravel MySQL Vue/React combination in the PHP development question and answer community is the first choice for Laravel MySQL Vue/React combination, due to its maturity in the ecosystem and high development efficiency; 2. High performance requires dependence on cache (Redis), database optimization, CDN and asynchronous queues; 3. Security must be done with input filtering, CSRF protection, HTTPS, password encryption and permission control; 4. Money optional advertising, member subscription, rewards, commissions, knowledge payment and other models, the core is to match community tone and user needs.

Choosing appropriate data types for columns in MySQL tables Choosing appropriate data types for columns in MySQL tables Jul 15, 2025 am 02:25 AM

WhensettingupMySQLtables,choosingtherightdatatypesiscrucialforefficiencyandscalability.1)Understandthedataeachcolumnwillstore—numbers,text,dates,orflags—andchooseaccordingly.2)UseCHARforfixed-lengthdatalikecountrycodesandVARCHARforvariable-lengthdata

mysql common table expression (cte) example mysql common table expression (cte) example Jul 14, 2025 am 02:28 AM

CTE is a temporary result set in MySQL used to simplify complex queries. It can be referenced multiple times in the current query, improving code readability and maintenance. For example, when looking for the latest orders for each user in the orders table, you can first obtain the latest order date for each user through the CTE, and then associate it with the original table to obtain the complete record. Compared with subqueries, the CTE structure is clearer and the logic is easier to debug. Usage tips include explicit alias, concatenating multiple CTEs, and processing tree data with recursive CTEs. Mastering CTE can make SQL more elegant and efficient.

mysql temporary table vs memory table mysql temporary table vs memory table Jul 13, 2025 am 02:23 AM

Temporary tables are tables with limited scope, and memory tables are tables with different storage methods. Temporary tables are visible in the current session and are automatically deleted after the connection is disconnected. Various storage engines can be used, which are suitable for saving intermediate results and avoiding repeated calculations; 1. Temporary tables support indexing, and multiple sessions can create tables with the same name without affecting each other; 2. The memory table uses the MEMORY engine, and the data is stored in memory, and the restart is lost, which is suitable for cache small data sets with high frequency access; 3. The memory table supports hash indexing, and does not support BLOB and TEXT types, so you need to pay attention to memory usage; 4. The life cycle of the temporary table is limited to the current session, and the memory table is shared by all connections. When choosing, it should be decided based on whether the data is private, whether high-speed access is required and whether it can tolerate loss.

Setting up semi-synchronous replication in MySQL Setting up semi-synchronous replication in MySQL Jul 15, 2025 am 02:35 AM

The steps for setting MySQL semi-synchronous replication are as follows: 1. Confirm the version supports and load the plug-in; 2. Turn on and enable semi-synchronous mode; 3. Check the status and operation status; 4. Pay attention to timeout settings, multi-slave library configuration and master-slave switching processing. It is necessary to ensure that MySQL 5.5 and above versions are installed, rpl_semi_sync_master and rpl_semi_sync_slave plugins, enable corresponding parameters in the master and slave library, and configure automatic loading in my.cnf, restart the service after the settings are completed, check the status through SHOWSTATUS, reasonably adjust the timeout time and monitor the plug-in operation.

Automating MySQL Deployments with Infrastructure as Code Automating MySQL Deployments with Infrastructure as Code Jul 20, 2025 am 01:49 AM

To achieve MySQL deployment automation, the key is to use Terraform to define resources, Ansible management configuration, Git for version control, and strengthen security and permission management. 1. Use Terraform to define MySQL instances, such as the version, type, access control and other resource attributes of AWSRDS; 2. Use AnsiblePlaybook to realize detailed configurations such as database user creation, permission settings, etc.; 3. All configuration files are included in Git management, support change tracking and collaborative development; 4. Avoid hard-coded sensitive information, use Vault or AnsibleVault to manage passwords, and set access control and minimum permission principles.

mysql incorrect string value for column mysql incorrect string value for column Jul 15, 2025 am 02:40 AM

MySQL error "incorrectstringvalueforcolumn" is usually because the field character set does not support four-byte characters such as emoji. 1. Cause of error: MySQL's utf8 character set only supports three-byte characters and cannot store four-byte emoji; 2. Solution: Change the database, table, fields and connections to utf8mb4 character set; 3. Also check whether the configuration files, temporary tables, application layer encoding and client drivers all support utf8mb4; 4. Alternative solution: If you do not need to support four-byte characters, you can filter special characters such as emoji at the application layer.

How to use PHP to develop product recommendation module PHP recommendation algorithm and user behavior analysis How to use PHP to develop product recommendation module PHP recommendation algorithm and user behavior analysis Jul 23, 2025 pm 07:00 PM

To collect user behavior data, you need to record browsing, search, purchase and other information into the database through PHP, and clean and analyze it to explore interest preferences; 2. The selection of recommendation algorithms should be determined based on data characteristics: based on content, collaborative filtering, rules or mixed recommendations; 3. Collaborative filtering can be implemented in PHP to calculate user cosine similarity, select K nearest neighbors, weighted prediction scores and recommend high-scoring products; 4. Performance evaluation uses accuracy, recall, F1 value and CTR, conversion rate and verify the effect through A/B tests; 5. Cold start problems can be alleviated through product attributes, user registration information, popular recommendations and expert evaluations; 6. Performance optimization methods include cached recommendation results, asynchronous processing, distributed computing and SQL query optimization, thereby improving recommendation efficiency and user experience.

See all articles