安装
方法一:
1.到MySQL官网下载MySQL Community版,(作者下载的是mysql-5.6.21)MySQL分为商业版(Enterprise)和社区版(Community),商业版是要收费的,社区版是免费的。
MySQL的Mac版安装包分为两种一种是DMG Archive,另一种是Compressed Tar。DMG的安装比较简单,只需要双击安装文件即可,Compressed Tar的安装请自行查找资料。
2.mysql的安装路径为:
![](https://img-blog.csdn.net/20141011181938072?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRGlhX1ZhbXBpcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
同时,MySQL会在/usr/local/mysql创建一个指向该文件夹的软链接(symbolic link),
![](https://img-blog.csdn.net/20141011182059566?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRGlhX1ZhbXBpcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
方法二:
利用homebrew进行安装。
安装路径位于
启动MySQL
启动:
- /usr/local/Cellar/mysql/5.6.21/bin/mysql.server start
重启:
- /usr/local/Cellar/mysql/5.6.21/bin/mysql.server restart
关闭:
- /usr/local/Cellar/mysql/5.6.21/bin/mysql.server stop
![](https://img-blog.csdn.net/20141027162807468?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRGlhX1ZhbXBpcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
使用MySQL
1. 为root创建密码
- mysqladmin -u root password "root" //初始化密码, 第二个root为密码
2. 修改root密码
- mysqladmin -u root -p password "admin"
3. 进入MySQL
4. 然后就可以执行MySQL命令了,千万记得每条命令要以;结尾。
5.创建新用户
- INSERT INTO User (Host, User, Password, ssl_cipher, x509_issuer, x509_subject) VALUES ('localhost', 'sloth', Password('sloth'), '', '', '');
6. 退出mysql
删除MySQL
- 1 sudo rm /usr/local/mysql
- 2 sudo rm -rf /usr/local/mysql*
- 3 sudo rm -rf /Library/StartupItems/MySQLCOM
- 4 sudo rm -rf /Library/PreferencePanes/My*
- 5 vim /etc/hostconfig (and removed the line MYSQLCOM=-YES-)
- 6 rm -rf ~/Library/PreferencePanes/My*
- 7 sudo rm -rf /Library/Receipts/mysql*
- 8 sudo rm -rf /Library/Receipts/MySQL*
- 9 sudo rm -rf /var/db/receipts/com.mysql.*
1:查看服务器上当前数据库
mysql> SHOW DATABASES;
2:创建一个数据库MYDB
mysql> CREATE DATABASE MYDB;
3:选择你所创建的数据库
mysql> USE MYDB;
(按回车键出现Database changed 时说明操作成功!)
4:查看现在的数据库表
mysql> SHOW TABLES;
5:创建一个数据库表
mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));
6:显示表的结构:
mysql> DESCRIBE MYTABLE;
7:往表中加入记录
mysql> insert into MYTABLE values ("hyq","M");
8:用文本方式将数据装入数据库表中(例如D:/mysql.txt)
mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;
9:导入.
sql文件命令(例如D:/mysql.sql)
mysql>use database;
mysql>source d:/mysql.sql;
10:删除表
mysql>drop TABLE MYTABLE;
11:清空表
mysql>delete from MYTABLE;
12:更新表中数据
mysql>update MYTABLE set sex="f" where name='hyq';
13.查看默认的编码格式:
mysql> show variables like "%char%";
14.查看test数据库的编码格式:
mysql> show create database test;
15.查看yjdb数据库的编码格式:
mysql> show create table yjdb;