Mysql-安装(Linux)
1、下载mysql
切换到/opt/app目录下,执行如下命令,下载mysql 5.7.38版本。
[root@ywxtdb app]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
解压安装包
[root@ywxtdb app]# tar -zxvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
2、创建用户、组
2.1 检查组是否存在
[root@ywxtdb app]# groups mysql groups: mysql: no such user
2.2 创建用户、关联组
[root@ywxtdb app]# groupadd mysql && useradd -r -g mysql mysql
2.3 创建工作空间
[root@ywxtdb app]# mkdir -p /data/mysql
赋权
[root@ywxtdb app]# chown mysql:mysql -R /data/mysql
3、修改配置文件
[root@ywxtdb app]# vim /etc/my.cnf
主要修改datadir
[mysqld] user=mysql datadir=/data/mysql socket=/data/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/data/mysql/mysql.err pid-file=/data/mysql/mysql.pid [client] port=3306 socket=/data/mysql/mysql.sock # # include all files from the config directory # !includedir /etc/my.cnf.d
4、安装
4.1 移动安装包
将解压好的安装包移动到/usr/local/下,然后修改安装包名称为mysql
[root@ywxtdb local]# mkdir -p /usr/local/mysql [root@ywxtdb local]# cp -r /opt/app/mysql-5.7.38-linux-glibc2.12-x86_64/* /usr/local/mysql
4.2 初始化
[root@ywxtdb local]# cd /usr/local/mysql/bin/ [root@ywxtdb local]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
【如需】如果初始化出错,可以重新配置后再行初始化
[root@ywxtdb bin]# rm -rf /data/mysql/*
初始化
[root@ywxtdb local]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
4.3 查看初始化密码
最后的初始化密码 root@localhost: hicdf.s1It%j BED+8i(X5)mf -vc4H_woi!+6
[root@ywxtdb bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize 2022-09-30T05:47:13.722877Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-09-30T05:47:14.169001Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-09-30T05:47:14.253178Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-09-30T05:47:14.315392Z 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: 55d33b5f-4083-11ed-83cb-000c29ad1e70. 2022-09-30T05:47:14.359460Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-09-30T05:47:14.602832Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-09-30T05:47:14.602861Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-09-30T05:47:14.604186Z 0 [Warning] CA certificate ca.pem is self signed. 2022-09-30T05:47:14.687867Z 1 [Note] A temporary password is generated for root@localhost: hicdf.s1It%j adh;w.=s>1lV BED+8i(X5)mf
4.4 启动mysql
添加服务启动
[root@ywxtdb bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动
[root@ywxtdb mysql]# service mysql start Starting MySQL. SUCCESS!
4.5 修改密码
1、开启免密登录
修改my.cnf文件
[root@ywxtdb mysql]# vim /etc/my.cnf
在mysqld模块下面添加 skip-grant-tables
转存失败重新上传取消
2、重启mysql
[root@ywxtdb mysql]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
3、登录mysql
上面开通免密后,可以直接Enter进入
[root@node1 bin] cd /usr/local/mysql/bin [root@node1 bin] ./mysql -u root -p
4、修改密码
use mysql; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; flush privileges;
5、修改远程连接
update user t set t.host = '%' where t.user = 'root'; flush privileges;