wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz mysql-8.0.30
增加用户组
groupadd mysql
增加用户
useradd -r -g mysql mysql
进入文件
cd mysql-8.0.30
pwd
usr/local/mysql-8.0.30
创建数据目录
mkdir data
chmod 777 /data
mkdir temp
chmod 777 ./temp
创建配置文件
cd support-files
vim my-default.cnf
[mysqld]
basedir = /usr/local/mysql-8.0.21
datadir = /data
port = 3306
socket = /usr/local/mysql-8.0.30/tmp/mysql.sock
[client]
default-character-set=utf8
socket= /usr/local/mysql-8.0.30/tmp/mysql.sock
[mysql]
default-character-set=utf8
socket= /usr/local/mysql-8.0.30/tmp/mysql.sock
请注意这些地址在你放mysql的地址位置。别写错了
修改当前目录权限
chown -R mysql:mysql ./
一定要写好 提权位置
初始化
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-8.0.30 --datadir=/usr/local/mysql-8.0.30/data
会输出一些信息 一定要记住
2022-09-06T14:10:30.386261Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 2hy0Ujwt<NHb
这里面有密码
开机自启
cd support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list mysql (检查是否启动成功)
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
启动成功
修改 profile
vim /etc/profile (配置环境变量)
export PATH=$PATH:/usr/local/tools/mysql-8.0.21/bin:/usr/local/tools/mysql-8.0.21/lib
wq 保存
启动服务
cd support-files
./mysql.server start
我这里报错了
/mysql.server: line 239: my_print_defaults: command not found
./mysql.server: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[FAILED]ld_safe)
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql-8.0.30
datadir=/data
在这个段下面新增这两个值保存退出
在启动
./mysql.server start
报错
Starting MySQL.2022-09-06T14:35:01.656469Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
继续修改
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
mkdir /var/log/mysql
chown -R mysql:mysql /var/log/mysql/
vim /etc/my.cnf
把上面的配置复制给他
登陆
mysql -u root -p
pVRie4S*c%TNq (密码是上面生成的密码,特殊符号可能报错,重新执行的初始化)