yum -y install make gcc-c++ cmake bison-devel ncurses-devel readline-devel libaio-devel perl libaio wget lrzsz vim libnuma* bzip2 xz
新建mysql用户
1 2
groupadd mysql useradd -r -g mysql -s /bin/false mysql
规划mysql数据目录
1
mkdir /opt/mysql
安装Mysql
下载Mysql
1 2 3
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
初始化mysql
1 2 3 4 5 6 7 8 9 10
cd /usr/local/mysql/bin/ ./mysqld --initialize --user=mysql --datadir=/opt/mysql 2021-12-31T03:06:17.837238Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-12-31T03:06:17.837469Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive. 2021-12-31T03:06:26.994083Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-12-31T03:06:28.532406Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-12-31T03:06:28.745765Z 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: a5d85ca0-69e6-11ec-8e9c-525400ef6113. 2021-12-31T03:06:28.768840Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-12-31T03:06:29.738532Z 0 [Warning] CA certificate ca.pem is self signed. 2021-12-31T03:06:29.867148Z 1 [Note] A temporary password is generated for root@localhost: rkYWw1.(vp_q #注意这里是root密码
[root@mysqldb-144 mysql]# systemctl status mysqld ● mysqld.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: active (running) since Fri 2021-12-31 11:21:51 CST; 27min ago Docs: man:systemd-sysv-generator(8) Process: 8155 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS) Process: 8165 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS) CGroup: /system.slice/mysqld.service ├─8173 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/mysql --pid-file=/opt/mysql/mysqldb-144.pid └─8409 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/mysql --plugin-dir=/usr/local/mysql/lib/plug...
Dec 31 11:21:50 mysqldb-144 systemd[1]: Starting LSB: start and stop MySQL... Dec 31 11:21:51 mysqldb-144 mysqld[8165]: Starting MySQL. SUCCESS! Dec 31 11:21:51 mysqldb-144 systemd[1]: Started LSB: start and stop MySQL.
修改密码
方法1
登录mysql,进行修改
1
mysql> alter user 'root'@'localhost' identified by 'passwd';
方法2
使用mysqladmin工具修改
1 2
mysqladmin -u root -p password new_pass #newpass是要设置的新密码 Enter password: #这里是输入之前的密码(初始化生成的)
方法3
mysql8.0以上版本使用mysql_native_password进行密码验证
1
mysql> ALTER USER 'root'@'localhost'IDENTIFIED WITH mysql_native_password BY 'new_pass';