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
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)