mysql源码安装

Linux环境

1、mysql下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

下载参考:

mysql源码安装_第1张图片

2、把下载的 MySQL 压缩包上传到 Linux 服务器

3、解压mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz

tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz

4、把解压后的文件移动到 /usr/local 目录下

mv mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/mysql

5、创建MySQL组合用户

groupadd mysql

useradd -r -g mysql mysql

6、创建数据存储目录

mkdir /usr/local/mysql/data

7、修改相关权限

chown -R mysql:mysql /usr/local/mysql

chmod -R 777 /usr/local/mysql/

8、MySQL初始化操作,记录临时密码

cd /usr/local/mysql/bin

./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

输出内容如下:

[root@hecs-399223 bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2023-10-27T06:29:18.581041Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-10-27T06:29:18.826360Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-10-27T06:29:18.868528Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-10-27T06:29:18.928878Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 288aaf07-7492-11ee-8151-fa163e92ea6c.
2023-10-27T06:29:18.931018Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-10-27T06:29:19.409290Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-10-27T06:29:19.409316Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-10-27T06:29:19.409839Z 0 [Warning] CA certificate ca.pem is self signed.
2023-10-27T06:29:19.670575Z 1 [Note] A temporary password is generated for root@localhost: Y2Eu.8du7Fi<

注意:复制保存 MySQL初始化密码 Y2Eu.8du7Fi<

9、创建MySQL配置文件 /etc/my.cnf,执行如下命令即可自动创建

cat > /etc/my.cnf <<EOF
[mysqld]
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=200
max_connect_errors=10
character-set-server=utf8mb4
default_authentication_plugin=mysql_native_password

[mysql]
default-character-set=utf8mb4

[client]
port=3306
default-character-set=utf8mb4
EOF

10、配置开机自启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

启动mysql

systemctl start mysqld

11、设置环境变量

echo "export PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile

source /etc/profile

12、通过临时密码登录MySQL并修改密码

#登录
mysql -u root -p
ALTER USER 'root' @'localhost' IDENTIFIED BY '123456';

flush privileges;

13、开启远程访问

grant all privileges on *.* to "root"@"%" identified by "123456";  

flush privileges;

13、开启远程访问

grant all privileges on *.* to "root"@"%" identified by "123456";  

flush privileges;

安装结束!

你可能感兴趣的:(数据库,mysql,数据库)