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.
to avoid some troubles, such as: after the installation is completed, the password cannot be set and the mysql library cannot be seen.
- 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
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. .
chown -R mysql.mysql /usr/local/mysql/*
- 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
scripts/mysql_install_db --user=mysql - -datadir=data directory
chown -R root /usr/local/mysql /*
- 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)
- 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
service mysqld start
View the startup status
netstat -tnlp
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
- 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)
[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'
vi /etc/man.config
添加一行
MANPATH /usr/local/mysql/man
保存退出
CREATE DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
# 创建一个本地登录的用户,并授予全部权限 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
(一)数据备份
# 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 < backupfile.sql # 2、导入数据( 常用source命令,进入某个数据库,指定备份的脚本文件) mysql> 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!