Without the Mac root password, the current user has sudo permission, so the command to execute as root is added sudo.
Is there a _mysql user and user group, and see if the user _mysql is a member of the user group _mysql.
Move the extracted code to the/usr/local/mysql directory.
#切换到/usr/local/mysql Directory
Cd/usr/local/mysql
#是否存在_mysql用户和用户组 and see if the user _mysql is not a member of the _mysql group
$ DSCL. -list/users|grep _mysql
$ DSCL. -list/groups|grep _mysql
$ dsmemberutil checkmembership-u _mysql-g _mysql
# from the official document, install MySQL only need to rely on users to run, do not need to log in. So when you think of installing, there is a user who is not logged in
$ sudo chown-r _mysql.
$ sudo chgrp-r _mysql.
$ sudo./scripts/mysql_install_db--user=_mysql--datadir=/usr/local/mysql/data
$ sudo chown-r root.
$ sudo chown-r _mysql./data
# Modify configuration file
#开启日志并调整下
Log_bin = Mysql-bin
Max-binlog-size = 10M
Expire_logs_days = 3
#根据输出日志作的添加选项
Explicit_defaults_for_timestamp
Lower_case_table_names = 2
#根据实际进行修改, the last User=_mysql parameter can only be started by the root user, and non-root users can use sudo
Basedir =/usr/local/mysql
DataDir =/usr/local/mysql/data
Port = 3306
server_id = 1
user = _mysql
#使用脚本管理 (start|stop|restart|reload|force-reload|status) MySQL
$ sudo cp support-files/mysql.server MySQL
$ sudo vim MySQL
#把东东都放到这目录, easy to delete later (runtime does not find the build lock file)
Basedir=/usr/local/mysql
Datadir= "$basedir/data"
Lock_file_path= "$basedir/mysql_lock"
#_mysql身份运行要在当前目录写入socket文件, so write permissions to the group
$ sudo chmod g+w.
#sudo MySQL start is wrong because it goes to $path to find the MySQL command
$ sudo./mysql start
#检查是否运行
$ ps-u _mysql
#第一次登录空密码, the other is not very different from Linux.
$ bin/mysql-h 127.0.0.1-u root-p
#初始化 MySQL Root Password
./bin/mysqladmin-u Root Password 123456