weiki@WeikideMacBook-Pro vim weiki@WeikideMacBook-Pro [mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 socket = /usr/local/mysql/data/mysql.sock log-error = /usr/local/mysql/data/mysqld.log
[client] socket=/usr/local/mysql/data/mysql.sock
为什么要放到 /usr/local/mysql
在 mysql/support-files/mysql.server 脚本里有如下描述
1 2 3 4 5 6 7 8 9 10 11
# If you install MySQL on some other places than /usr/local/mysql, then you # have to do one of the following things for this script to work: # # - Run this script from within the MySQL installation directory # - Create a /etc/my.cnf file with the following information: # [mysqld] # basedir=<path-to-mysql-installation-directory> # - Add the above to any other configuration file (for example ~/.my.ini) # and copy my_print_defaults to /usr/bin # - Add the path to the mysql-installation-directory to the basedir variable # below.
weiki@WeikideMacBook-Pro cd /usr/local/mysql weiki@WeikideMacBook-Pro mysql % sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2022-09-27T06:43:30.004016Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process 85541 2022-09-27T06:43:30.008139Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive 2022-09-27T06:43:30.014427Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-09-27T06:43:30.062437Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-09-27T06:43:30.633461Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: XW?s4SjtJM*g 2022-09-27T06:43:30.949707Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.30). weiki@WeikideMacBook-Pro sudo support-files/mysql.server start # 看到这些信息就代表 mysql启动成功 Starting MySQL .Logging to '/usr/local/mysql/data/WeikideMacBook-Pro.local.err'. SUCCESS!
weiki@WeikideMacBook-Pro mysql % /usr/local/mysql/bin/mysql -uroot -P3306 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.30
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
修改密码
mac本地mysql的密码,自己设置一个好记的就ok了
1 2 3 4 5 6
mysql> alter user 'root'@'localhost' identified by '123456' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
启动&重启&停止&状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#启动 sudo /usr/local/mysql/support-files/mysql.server start # 重启 weiki@WeikideMacBook-Pro mysql % sudo /usr/local/mysql/support-files/mysql.server restart Password: Shutting down MySQL .. SUCCESS! Starting MySQL . SUCCESS! # 查看状态 weiki@WeikideMacBook-Pro mysql % sudo /usr/local/mysql/support-files/mysql.server status SUCCESS! MySQL running (9568) # 停止 weiki@WeikideMacBook-Pro sudo /usr/local/mysql/support-files/mysql.server stop
weiki@WeikideMacBook-Pro vim ~/.bash_profile # 增加这些内容 export MYSQL=/usr/local/mysql export PATH=$PATH:$MYSQL/bin # 让配置生效 weiki@WeikideMacBook-Pro source ~/.bash_profile # 全局变量生效 weiki@WeikideMacBook-Pro mysql % mysql -uroot -P3306 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>