Article directory
-
- 1. Download the MySQL installation package
- 2. Upload the MySQL installation package to the Linux server
- 3. Unzip the MySQL installation package
- 4. Create the MySQL data storage directory and authorize it
- 5. Create a MySQL group: Create a MySQL user and set a password
- 6. Create the MySQL installation initialization configuration file my.cnf in /etc in the system root directory
- 7.Initialize MySQL
- 8. Start the MySQL service
Linux系统版本:CentOS 8.3 64位
MySQL版本:mysql-8.0.25-linux-x86_64
1. Download the MySQL installation package
- Download address: https://dev.mysql.com/downloads/mysql
2. Upload the MySQL installation package to the Linux server
- Use Xftp to upload files (any other ftp software can be used) The storage path here is customized by me (can be uploaded directly to a customized directory)
- Note: The default installation path of MySQL is /usr/local/mysql (if the path changes, subsequent configuration may have some impact)
3. Unzip the MySQL installation package
- Enter the MySQL installation package storage path
cd 路径cd
例: /usr/libo/environment
ll 查看路径下所有目录
- Extract the .xz file to .tar
xz -d .xz文件名称
例:xz -d mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz
- Unzip the MySQL .tar installation package
tar -xvf .tar文件名称
例:tar -xvf mysql-8.0.25-linux-glibc2.12-x86_64.tar
- Decompression completed
- Modify the MySQL file name (the name is too long, it is recommended to modify it)
mv 原目录名称 新目录名称
例:mv mysql-8.0.25-linux-glibc2.12-x86_64 mysql-8.0.25
4. Create the MySQL data storage directory and authorize it
- After entering the MySQL directory, use the command to create the MySQL data directory. The name can be chosen by yourself, for example: data
mkdir 目录名
- Authorize the MySQL directory (including the MySQL data storage directory)
chmod能改变权限,-R是目录下所有文件,777就是高权限(读、写、执行)
chmod -R 777 * 意思就是将当前目录下所有文件都给予777权限
5. Create a MySQL group: Create a MySQL user and set a password
- Add user, set password
添加用户:useradd 用户名
设置密码:passwd 用户名
- Grant permissions to the mysql directory to the mysql user and mysql group
chown -R mysql:mysql /usr/libo/environment/mysql-8.0.25
- Note: When setting the password, if it is less than 8 characters, a prompt will appear. Just fill it in again. It will not affect the password.
6. Create the MySQL installation initialization configuration file my.cnf in /etc in the system root directory
- The content is as follows:
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/libo/environment/mysql-8.0.25
# 设置mysql数据库的数据的存放目录
datadir=/usr/libo/environment/mysql-8.0.25/data
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
- Use commands or modify the my.cnf file directly in ftp
vi /etc/my.cnf
按下i健进入 insert模式进行修改,完成后按下esc键再后输入 :wq 保存并退出(英文模式下,注意wq前面还有冒号:)
7.Initialize MySQL
- Enter the bin directory of MySQL
cd /usr/libo/environment/mysql-8.0.25/bin
- Execute the command and remember the random password produced (will be used when changing the password later)
./mysqld --initialize --console
8. Start the MySQL service
- Run the MySQL service
cd /usr/libo/environment/mysql-8.0.25/support-files
./mysql.server start
- Possible problems and solutions during startup:
1. When starting the MySQL service, an updating PID file error occurs.
Solution: Re-authorize in the installation directory, and then start MySQL
chmod -R 777 /usr/libo/environment/mysql-8.0.25
chmod -R 777 /usr/libo/environment/mysql-8.0.25/data
2. When starting the MySQL service, it reports my_print_defaults: Command not found. Solution
: Check and modify the MySQL installation directory in /etc/my.cnf.
3. If it is confirmed that there is no problem with the MySQL installation path, it is likely that our my is not read. .cnf configuration file
As you can see in the mysql.server file, the default path of MySQL is /usr/local/mysql because we customize the path. So you need to establish a connection to the my.cnf file
将mysql目录下的bin/my_print_defaults链接到/usr/bin目录下。
cd /usr/bin
sudo ln -s /usr/libo/environment/mysql-8.0.25/bin/my_print_defaults
为什么需要my_print_defaults呢?这是因为mysql.server执行时就是通过my_print_defaults来读取my.cnf配置变量的。
Reference blog: https://blog.csdn.net/u012794845/article/details/86577399
- Add MySQL to the system process
将MySQL加入系统进程中
cp mysql.server /etc/init.d/mysql
然后重启MySQL服务
service mysql restart
- Change login password
进入MySQL 密码是之前自动生成的密码
./mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
- Set up to allow remote login
use mysql 切换数据库
update user set user.Host='%' where user.User='root'; 修改HOST为%
flush privileges; 修改成功后刷新权限
- Exit MySQL
quit;
- Restart the MySQL service
service mysql restart
- Test remote connection