search
HomeDatabaseMysql TutorialHow to add mysql to Red Hat system

How to add mysql to the Red Hat system: first log in to the Red Hat system as the root user; then create the mysql user and mysql group; then set the data storage directory; finally enter the mysql directory, manually execute the database initialization script and Just make relevant configuration file modifications.

How to add mysql to Red Hat system

Compile and install MySQL in Redhat Red Hat system
0. Log in to the system as the root user and perform the following operations

to avoid some troubles, such as: after the installation is completed, the password cannot be set and the mysql library cannot be seen.

1. Decompress the universal binary compressed package to /usr/local according to the official requirements, and the directory name must be mysql
  • Enter the compressed package directory, Execute the following command to decompress
    tar xf mysql****.tar.gz -C /usr/local
  • Create link
    cd /usr/local
    ln -sv mysql* **** mysql
2. Create mysql user mysql group (those with more than 500 are not system users, and system users do not have home directories)

groupadd -r -g 306 mysql
useradd -r -g 306 -u 306 mysql

Enter the mysql directory, there is an INSTALL-BINARY file with specific installation instructions. .

3. Modify the owner group of all files in the mysql directory

chown -R mysql.mysql /usr/local/mysql/*

4. Set the data storage directory
  • Create the data directory: (Specify as needed)
  • Modify the data directory permissions:
    chown -R mysql .mysql data directory (specify the owner group of the data directory is the mysql user mysql group)
    chmod o-rx data directory (other users do not have any permissions)
    Ensure that the owner group of the data directory is mysql , other users do not have any permissions
5. Enter the mysql directory and manually execute the database initialization script

scripts/mysql_install_db --user=mysql - -datadir=data directory

6. After the script is executed, change the owner of the mysql directory to root

chown -R root /usr/local/mysql /*

7. There is mysql.server (mysql startup script) in the mysql/support-files directory
  • Copy and rename the script
    cp support-files/mysql.server /etc/init.d/mysqld
  • Check whether mysqld has execution permission, if not, give execution permission
  • Add mysqld to the service list
    chkconfig --add mysqld
  • Check whether automatic startup is enabled
    chkconfig --list mysqld (2 3 4 5 is on)
8, this Mysqld cannot be started yet, you need to modify the configuration file
  • Default location: /etc/my.cnf
  • The way mysql reads the configuration file is very unique
    Mysql configuration file is fragmented and centralized (can be configured for multiple services)
[mysql]——客户端配置
[mysqld]——服务端配置
[client]——对所有的客户端程序都生效
  • mysql reads the configuration file Sequence:
    /etc/my.cnf --> /etc/mysql/my.cnf
    --> $BASEDIR/my.cnf (usually the installation directory)
    --> ~ /.my.cnf (the configuration file in the user’s home directory, even if the mysql user does not have a home directory, search it again)

#If there is a conflict between the four configuration files found, the last One shall prevail (the latter one overwrites the previous one
Mysql can run even without any configuration files. A bunch of default configuration files are provided in the support-files directory

  • Copy a configuration file to /etc/my.cnf
    cp support-files/my-large.cnf /etc/my.cnf
  • Edit and modify the configuration file
    vi /etc/my.cnf
  • Add the data directory configuration information to the [mysqld] fragment, it is very important
    datadir = /data directory
9. Start the mysqld service

service mysqld start
View the startup status
netstat -tnlp

10. Enter the mysql database

Execute mysql and find that the command cannot be found
Check ls /usr/local/mysql/bin/ and find that there is a mysql command
Need to add the mysql command to the system directory
Create a script File:
vi /etc/profile.d/mysql.sh
Add export PATH=$PATH:/usr/local/mysql/bin
Save and exit
Log in again and execute mysql again. Enter the mysql database

11. The mysql server maintains two types of variables
  • Server variables: Define the operating characteristics of the MySQL server
    View command: show global variables [like 'data%'] (used during tuning)
  • Status variables: Save the statistical data when the MySQL server is running
    View command: show global status [like 'datadir'] (real-time monitoring Use)
12. Set password

[Method 1] Execute at the mysql prompt
mysql>set password for 'username'@ 'host'=password('password');
After modifying user information, reread the authorization table
mysql>flush privileges;

[方法二]在Linux命令提示符下执行
# mysqladmin -uUsername -hHost -p password 'password'(如果没有密码可以省略-p)

[方法三]修改mysql库中的user表
update user set Password=password("password") where user="user" and host="***"

创建mysql的root用户远程访问(对所有库.所有表)
mysql>grant all privileges on . to 'root'@'192.16.%.%' identified by "password";

重读授权表
mysql>flush privileges;

[方法四]安装完之后提示的密码修改方式:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

13、将mysql帮助文档添加至帮助命令

vi /etc/man.config
添加一行
MANPATH /usr/local/mysql/man
保存退出

14、创建数据库并指定字符集
CREATE DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
15、创建用户用于SqlYog登录
#  创建一个本地登录的用户,并授予全部权限
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     WITH GRANT OPTION;

# 创建一个远程登录用户,并授予全部权限
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     WITH GRANT OPTION;

# 最厚要刷新一下授权表
mysql> flush privileges;

原文: Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

16、数据备份与恢复

(一)数据备份

#  1、备份一个数据库(根据提示输入密码,如果备份远程数据库,需要加上 -h 参数)
$ mysqldump -h host -u username -p database_name > back_name.sql

# 2、备份 test 数据库中的 emp 表(根据提示输入密码)
 $ mysqldump -u username -p test emp > emp.sql

# 3、备份 test 数据库中的 emp 表 和 dept 表(根据提示输入密码)
 $ mysqldump -u username -p test emp dept > emp_dept.sql

# 4、备份多个数据库
$ mysqldump -hhostname -uusername -ppassword  databasename1  databasename2> multibackupfile.sql

# 5、备份所有的数据库
$ mysqldump –all-databases > allbackupfile.sql

# 6、只备份数据库结构
$ mysqldump  –no-data  –databases databasename1 databasename2 databasename3 > structurebackupfile.sql

(二)数据恢复

# 1、还原数据库(根据提示输入密码,如果备份远程数据库,需要加上 -h 参数)
$ mysql -hhostname -uusername -ppassword databasename  source d:\test.sql

# 3、将数据库迁移至新服务器
$ mysqldump -uusername -ppassword databasename | mysql –host=*.*.*.* -C databasename

The above is the detailed content of How to add mysql to Red Hat system. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

MySQL: How to Add a User RemotelyMySQL: How to Add a User RemotelyMay 12, 2025 am 12:10 AM

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

The Ultimate Guide to MySQL String Data Types: Efficient Data StorageThe Ultimate Guide to MySQL String Data Types: Efficient Data StorageMay 12, 2025 am 12:05 AM

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

MySQL BLOB vs. TEXT: Choosing the Right Data Type for Large ObjectsMySQL BLOB vs. TEXT: Choosing the Right Data Type for Large ObjectsMay 11, 2025 am 12:13 AM

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

MySQL: Should I use root user for my product?MySQL: Should I use root user for my product?May 11, 2025 am 12:11 AM

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQL String Data Types Explained: Choosing the Right Type for Your DataMySQL String Data Types Explained: Choosing the Right Type for Your DataMay 11, 2025 am 12:10 AM

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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 Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools