首页 > 代码库 > mac安装mysql

mac安装mysql

brew install mysql
2. 在 /usr/local/etc/ 下创建或修改 my.cnf,示例:

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8

[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
init-connect =‘SET NAMES utf8‘
max_allowed_packet = 64M
bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock
innodb_file_per_table=1

[mysqld_safe]
timezone = ‘+0:00‘
3. 赞安装完 mysql 后,他会提示你 init database,并提供下面这两句让你执行,很可能你没执行这两句

$ unset TMPDIR
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
4. 然后就可以指向 mysql.server start 来启动了,为了安全,你还可以执行安全设置向导,根据提示一步一步配置

 

 

 

 

 

 

 

1.1 打开系统偏好设置,如果你的电脑已经安装MySQL,会在下面有一个mysql的按钮。点进去关闭mysql服务。
关闭myql

1.2 打开一个终端,输入一下命令

$ cd /usr/local/mysql/bin
$ sudo su
1
2
1
2
然后便可以看到终端命令变成这个开头: sh-3.2#
输入一下命令

sh-3.2#./mysqld_safe --skip-grant-tables &
1
1
之后边可以以安全模式进入数据库了。

1.3 现在打开一个新的终端
输入以下命令:

mysql -u -root

SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘newpass‘);


update user set authentication_string=password(‘root‘) where Host=‘localhost‘ and User=‘root‘;

$ mysql_secure_installation

 

 

 

e‘ve installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -uroot

To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don‘t want/need a background service you can just run:
mysql.server start

mac安装mysql