1 website Download, link https://www.mysql.com/downloads/
Download MySQL Community Server
The default is for you to choose the Mac OS X platform
The choice is. dmg. Click Download on the right to download.
Jump to another interface to indicate that you need not register, directly select the bottom "no thanks,just take Me to downloads!"
2 installing MySQL
Terminal input after installation is complete:
$mysql-version
-bash:mysql:command not found
"/usr/local/mysql/bin/mysql" is the default installation path for MySQL:
$/usr/local/mysql/bin/mysql-version
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/tmp/mysql.sock ' (2)
$CD/usr/local/bin
$sudo Ln-fs/usr/local/mysql/bin/mysql MySQL
Password:
$mysql-version
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/tmp/mysql.sock ' (2)
Configure the password of the root account, the default is not configured,
$ mysql-u Root
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3
Server version:5.7.18 MySQL Community Server (GPL)
Copyright (c), Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
Mysql>update mysql.user Set authentication_string = password (' ****** ') where user = ' root ';
Query OK, 1 row affected, 1 Warning (0.00 sec)
Rows matched:1 changed:1 warnings:1
mysql> flush Privileges;
Mysql> quit
Flush privileges After mysql-u root is not logged on, need to use a password such as the following
$mysql-U Root
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)
Mysql-u root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 5
Server version:5.7.18 MySQL Community Server (GPL)
Copyright (c), Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
mysql> CREATE DATABASE homework;
ERROR 1820 (HY000): Must reset your password using ALTER USER statement before executing this statement.
There is an error, the workaround: Reset the password again
mysql> Set Password =password (' ****** ');
Query OK, 0 rows affected, 1 Warning (0.00 sec)
mysql> CREATE DATABASE homework;
Query OK, 1 row Affected (0.00 sec)
Mysql> use homework;
Database changed
Mysql> Show tables;
Empty Set (0.00 sec)
Base operation of the database, create the database.
Mysql> CREATE TABLE Student (Sno Int (ten), Sname varchar (255), Ssex varchar (255), Sage Int (ten), sdept varchar (255));
Query OK, 0 rows affected (0.03 sec)
Mysql> Show tables;
+--------------------+
| Tables_in_homework |
+--------------------+
| Student |
+--------------------+
1 row in Set (0.00 sec)
To view the information statement that created the table:
Mysql> Show CREATE TABLE Student;
+---------+------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ---------------------------+
| Table | Create table &NBSP ; , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp |
+---------+---------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ------------------------+
| Student | CREATE TABLE ' Student ' (
' Sno ' int (ten) is DEFAULT NULL,
' Sname ' varchar (255) DEFAULT NULL,
' Ssex ' varchar (255) DEFAULT NULL,
' Sage ' int (ten) DEFAULT NULL,
' sdept ' varchar (255) DEFAULT NULL
) Engine=innodb DEFAULT charset=latin1 |
+---------+---------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ------------------------+
1 row in Set (0.02 sec)
Mysql> CREATE TABLE Course (Con int), Cname varchar (255), Cpno Int (ten), Ccredit Int (10));
Query OK, 0 rows affected (0.03 sec)
Mysql> Show CREATE TABLE Course;
+--------+----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------+
| Course | CREATE TABLE ' Course ' (
' Con ' int (ten) DEFAULT NULL,
' Cname ' varchar (255) DEFAULT NULL,
' Cpno ' int (ten) is DEFAULT NULL,
' Ccredit ' int (ten) DEFAULT NULL
) Engine=innodb DEFAULT charset=latin1 |
+--------+----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------+
1 row in Set (0.00 sec)
Insert a piece of data:
mysql> INSERT into Course values (' 4 ', ' data structure ', ' 7 ', ' 4 ');
Query OK, 1 row Affected (0.00 sec)
Update one piece of data:
mysql> Update Course set cno= ' 5 ' where cname= ' data structure ';
ERROR 1054 (42S22): Unknown column ' Cno ' in ' Field list '
Found the created field should be CNO, created wrong, con
To change a field:
mysql> ALTER TABLE Course change Con Cno int (10);
Query OK, 0 rows affected (0.02 sec)
records:0 duplicates:0 warnings:0
mysql> Update Course set cno= ' 5 ' where cname= ' data structure ';
Query OK, 1 row affected (0.01 sec)
Rows matched:1 changed:1 warnings:0
Query data:
Mysql> select * from Course;
+------+--------------------+------+---------+
| Cno | Cname | Cpno | Ccredit |
+------+--------------------+------+---------+
| 1 | Database | 5 | 4 |
| 2 | Math | 0 | 2 |
| 3 | Information System | 1 | 4 |
| 4 | Operation System | 6 | 3 |
| 5 | Data Structure | 7 | 4 |
| 6 | Data Process | 0 | 2 |
| 7 | Pascal | 6 | 4 |
+------+--------------------+------+---------+
7 Rows in Set (0.00 sec)
MySQL installation and basic operation (MySQL job)