Solve the problem of no my.cnf file in /etc when installing mysql on Linux

Solve the problem of no my.cnf file in /etc when installing mysql on Linux

Today I wanted to change the mysql port, but I found that there was no my.cnf file in my /etc/ directory, so I looked online to see if there was a solution.

I have read many blogs about the lack of my.cnf under Linux, all of which said to move my-medium.cnf to etc and rename it to my.cnf, but I don’t have my-medium.cnf either. Later I learned that starting from 5.7.18, the official no longer provides the my-default.cnf file in the binary package.

For details, please refer to: https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

So how do we change the port number? In fact, we only need to modify /etc/mysql/mysql.conf.d.

Supplement: When mysql is started, it prompts that /etc/my.cnf is ignored.

Today, I was dealing with a problem with a test developer and found a MySQL instance startup failure. The process was as follows:

It is found that the MySQL instance is closed. There is a warning when executing the command to start the MySQL instance:

# service mysql.server start
Warning: World-writable config file '/etc/my.cnf' is ignored
Starting MySQL SUCCESS!

Observe the mysql startup log, which shows:

151014 11:39:24 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data
Warning: World-writable config file '/etc/my.cnf' is ignored

It probably means that the permissions are globally writable and any user can write. MySQL is worried that this file may be modified maliciously by other users, so it ignores this configuration file. This way mysql cannot be shut down.

At this time, when querying the configuration in the MySQL database, it is found that some parameters configured in my.cnf are not effective in the MySQL instance.

This is because /etc/my.cnf has also been modified to 777 permissions:

# ls -la /etc/my.cnf
-rwxrwxrwx 1 root root 1120 Jul 31 10:28 /etc/my.cnf

/etc/my.cnf has too many permissions, which will affect the instance's inability to start or shut down. It needs to be modified to 644. The operation is as follows:

# ls -la /etc/my.cnf
-rwxrwxrwx 1 root root 1120 Jul 31 10:28 /etc/my.cnf
# 
# 
# chmod 644 /etc/my.cnf
# 
# ls -la /etc/my.cnf
-rw-r--r-- 1 root root 1120 Jul 31 10:28 /etc/my.cnf
#

Confirm /etc/my.cnf and restart the instance:

151014 14:05:54 mysqld_safe mysqld from pid file /data/mysql/data/yq-xg-dev122.pid ended
151014 14:06:08 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data
151014 14:06:08 [Note] Plugin 'FEDERATED' is disabled.
151014 14:06:08 InnoDB: The InnoDB memory heap is disabled
151014 14:06:08 InnoDB: Mutexes and rw_locks use GCC atomic builtins
151014 14:06:08 InnoDB: Compressed tables use zlib 1.2.3
151014 14:06:08 InnoDB: Using Linux native AIO
151014 14:06:08 InnoDB: Initializing buffer pool, size = 128.0M
151014 14:06:08 InnoDB: Completed initialization of buffer pool
151014 14:06:08 InnoDB: highest supported file format is Barracuda.
151014 14:06:08 InnoDB: Waiting for the background threads to start
151014 14:06:09 InnoDB: 1.1.8 started; log sequence number 18872844901
151014 14:06:09 [Warning] 'proxies_priv' entry '@ root@xinge122' ignored in --skip-name-resolve mode.
151014 14:06:09 [Note] Event Scheduler: Loaded 0 events
151014 14:06:09 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.5.19-log' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)

You can see that after modifying the /etc/my.cnf permissions to normal, the MySQL instance can be started normally.

The following inspirations can be obtained from this case:

Modifying the permissions of directories and files in the root directory of the Linux operating system is very dangerous;

For example, if the permissions of the /etc/ssh directory are modified, ssh cannot be used; if the /etc/security or /etc/init.d/sshd files are modified, the root user cannot log in to the system;

Therefore, you must pay attention to system permissions, especially file permissions under the /etc/ directory, which cannot be modified casually.

Both development and operation and maintenance need to be standardized, and direct operations as the root user should be avoided as much as possible; the storage location of software and applications should also be placed in a separate directory, and each application should be operated by a separate user;

Do not modify system files easily, especially do not modify /etc/ related system files casually. If you want to modify them, you can test them first and make sure there are no problems before making any modifications.

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • MySQL multi-instance deployment and installation guide under Linux
  • MySQL 8.0.25 installation and configuration tutorial under Linux
  • mysql8.0.23 linux (centos7) installation complete and detailed tutorial
  • Steps to install MySQL using Docker under Linux
  • Aliyun Linux compile and install php7.3 tengine2.3.2 mysql8.0 redis5 process detailed explanation
  • Detailed tutorial on installing MySQL database in Linux environment
  • Detailed tutorial on installing mysql-8.0.20 under Linux
  • Tutorial on installing MySQL under Linux

<<:  HTML table markup tutorial (18): table header

>>:  Detailed tutorial on running multiple Springboot with Docker

Recommend

How to use JSX to implement Carousel components (front-end componentization)

Before we use JSX to build a component system, le...

Coexistence of python2 and python3 under centos7 system

The first step is to check the version number and...

Summary of the benefits of deploying MySQL delayed slaves

Preface The master-slave replication relationship...

A brief understanding of the differences between MySQL InnoDB and MyISAM

Preface MySQL supports many types of tables (i.e....

Detailed explanation of Vue development website SEO optimization method

Because the data binding mechanism of Vue and oth...

View the dependent libraries of so or executable programs under linux

View the dependent libraries of so or executable ...

Example of how to configure the MySQL database timeout setting

Table of contents Preface 1. JDBC timeout setting...

JavaScript to achieve dynamic table effect

This article shares the specific code for JavaScr...

MySQL should never write update statements like this

Table of contents Preface cause Phenomenon why? A...

mysql error number 1129 solution

SQLyog connects to mysql error number 1129: mysql...

How to insert 10 million records into a MySQL database table in 88 seconds

The database I use is MySQL database version 5.7 ...

Why should you be careful with Nginx's add_header directive?

Preface As we all know, the nginx configuration f...