压缩版MySQL57安装
1. 下载解压包
https://downloads.mysql.com/archives/community/ 下载macos版 5.7.31
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-macos10.14-x86_64.tar
2. 加压添加bin到PATH
3. 执行mysql --initialize命令,获取初始化密码
% mysqld --initialize --basedir=/usr/local/mysql57 --datadir=/usr/local/mysql57/data
2023-10-26T14:16:19.384759Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-10-26T14:16:19.387151Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2023-10-26T14:16:19.446873Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-10-26T14:16:19.455154Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-10-26T14:16:19.456922Z 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: 3baa33c8-740a-11ee-9c00-0b102fbb1f67.
2023-10-26T14:16:19.501587Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2023-10-26T14:16:19.727493Z 0 [Warning] CA certificate ca.pem is self signed.
2023-10-26T14:16:19.841950Z 1 [Note] A temporary password is generated for root@localhost: wtYMm38?4mDZ
4. 启动mysqld
5. 客户端登录
mysql -uroot -p wtYMm38?4mDZ
如果登录不成功, 执行 mysqld --console --skip-grant-tables后,在执行下面的命令
6. 修改密码
使用命令进入mysql管理界面
mysql -u root -p
mysql> flush privileges;
mysql> grant all privileges on *.* to root@'localhost' identified by 'root'; (好像不如上一句管用)
mysql> use mysql;
mysql> **【必须有】** ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> **【必须有】** update user set authentication_string=password('12345') where user='root';
mysql> update user set host = '%' where user = 'root';
mysql> update user set password_expired='N' where user='root';
mysql> flush privileges;
7. my.cnf方式配置mysql
cat /etc/my.cnf
[mysql]
socket=/usr/local/mysql57/mysql.sock
[mysqld]
user=mysql
basedir=/usr/local/mysql57/
datadir=/usr/local/mysql57/data/
socket=/usr/local/mysql57/mysql.sock
【ERROR】集锦
【error】执行mysql -uroot时,一直提示
mjli@mjdeMacBook-Pro mysql57 % mysql -uroot -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
【解决】在my.cnf的 [mysql] 标签中增加socket=配置:
socket=/usr/local/mysql57/mysql.sock
【error】执行mysqld时,提示:[ERROR] Fatal error: Can’t change to run as user ‘mysql’ ; Please check that the user exists!
【解决】1)、创建mysql用户
useradd mysql
2)、mysql目录改为mysql读写权限
chown -R mysql:mysql /usr/local/mysql57
chown -R mysql:mysql /usr/local/mysql57