How to add mysql to Red Hat system

藏色散人
Release: 2020-11-13 10:05:10
Original
2444 people have browsed it

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

Recommended: "mysql video tutorial"
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]——对所有的客户端程序都生效
Copy after login
  • 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;
Copy after login
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;
Copy after login

原文: 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
Copy after login

(二)数据恢复

# 1、还原数据库(根据提示输入密码,如果备份远程数据库,需要加上 -h 参数) $ mysql -hhostname -uusername -ppassword databasename < backupfile.sql # 2、导入数据( 常用source命令,进入某个数据库,指定备份的脚本文件) mysql> source d:\test.sql # 3、将数据库迁移至新服务器 $ mysqldump -uusername -ppassword databasename | mysql –host=*.*.*.* -C databasename
Copy after login

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!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!