Mac安装MySQL及简单使用

系列 - MacOS好用工具软件

最近在学习MySQL,需要在Mac上安装MySQL,记录一下安装使用过程。

shell

brew install mysql

shell

brew services start mysql

shell

mysql_secure_installation

shell

mysql -uroot -p

shell

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

shell

exit

shell

brew services restart mysql

shell

mysql -uroot -p

shell

create database test;

shell

show databases;

shell

drop database test;

toml

brew services start mysql #: 启动 MySQL 服务器,并设置为自启动。
brew services stop mysql #: 停止 MySQL 服务器,并设置为不自启动。
brew services run mysql #: 只启动 MySQL 服务器。
mysql.server start #: 启动 MySQL 服务器。
mysql.server stop #: 停止 MySQL 服务器

执行上面的安装和启动后,就可以使用MySQL了。

shell

mysql -uroot -p

shell

create database mysite DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

shell

show databases;

shell

use mysite;

shell

CREATE TABLE `app_userinfo` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `is_active` tinyint(1) NOT NULL,
  `is_staff` tinyint(1) NOT NULL,
  `is_superuser` tinyint(1) NOT NULL,
  `date_joined` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

shell

desc app_userinfo;
【Mac安装MySQL】