下载:
64位系统的zip包:https://dev.mysql.com/downloads/mysql/
下载zip的包:C:Program FilesMySQLmysql-8.0.11-winx64
配置环境变量:
变量名:MYSQL_HOME
变量值:C:Program FilesMySQLmysql-8.0.11-winx64
生成data文件:
以管理员身份运行cmd
进入C:Program FilesMySQLmysql-8.0.11-winx64in 下
执行命令:mysqld --initialize-insecure --user=mysql 在C:Program FilesMySQLmysql-8.0.11-winx64目录下生成data目录
第一张图是直接CMD,第二张图是管理员权限下走的。如果不用管理员身份运行,将会因为权限不够而出现错误:Install/Remove of the Service Denied!)
ini 等配置不是本文的重点这个文件的配置可以参考 百度上各种文章,
这个时候你mysqld --install 之后 mysqld --initialize 等都没有报错的情况下 进行net start mysql
这个时候还是提示 MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。。
输入mysqld --console 吧信息打印到控制台 然后寻找一下信息中有没有出现
2018-10-17T12:35:16.437782Z 0 [ERROR] Can’t start server: Bind on TCP/IP port: No such file or directory
2018-10-17T12:35:16.437782Z 0 [ERROR] Can’t start server: Bind on TCP/IP port: No such file or directory
2018-10-17T12:35:16.439025Z 0 [ERROR] Do you already have another mysqld server running on port: 3306 ?
2018-10-17T12:35:16.450300Z 0 [ERROR] Aborting
这几个错误,如果有就继续看下去。如果是不一样的错误的话我相信你已经有新的思路去找问题了。
输入netstat -aon|findstr “3306” 去查找占用了3306端口的进程id
然后打开任务管理器 到详细找到刚才看到的进程id 结束掉然后运行 net start mysql 就可以运行了
登录mysql:
登录mysql:(因为之前没设置密码,所以密码为空,不用输入密码,直接回车即可)
C:Program FilesMySQLmysql-8.0.11-winx64in>mysql -u root -p
Enter password:
查询用户密码:
查询用户密码命令:mysql> select host,user,authentication_string from mysql.user;
设置(或修改)root用户密码:
设置(或修改)root用户密码:
mysql> update mysql.user set authentication_string=password("123456") where user
="root"; #password("123456"),此处引号中的内容是密码,自己可以随便设置
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; #作用:相当于保存,执行此命令后,设置才生效,若不执行,还是之前的密码不变
Query OK, 0 rows affected (0.01 sec)
退出mysql:
mysql> quit
Bye
C:WINDOWSsystem32>cd C:Program FilesMySQLmysql-8.0.11-winx64in
C:Program FilesMySQLmysql-8.0.11-winx64in>mysqld --install
The service already exists!
The current server installed: "C:Program FilesMySQLmysql-8.0.11-winx64inmysqld" MySQL
C:Program FilesMySQLmysql-8.0.11-winx64in>mysqld --install
The service already exists!
The current server installed: "C:Program FilesMySQLmysql-8.0.11-winx64inmysqld" MySQL
C:Program FilesMySQLmysql-8.0.11-winx64in>mysqld --initialize --user=root --console
2019-01-16T14:49:18.753197Z 0 [System] [MY-013169] [Server] C:Program FilesMySQLmysql-8.0.11-winx64inmysqld.exe (mysqld 8.0.11) initializing of server in progress as process 19372
2019-01-16T14:49:18.966798Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2019-01-16T14:49:18.997031Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-01-16T14:49:19.033327Z 0 [System] [MY-010910] [Server] C:Program FilesMySQLmysql-8.0.11-winx64inmysqld.exe: Shutdown complete (mysqld 8.0.11) MySQL Community Server - GPL.
C:Program FilesMySQLmysql-8.0.11-winx64in>net start mysql
MySQL 服务正在启动 ....
MySQL 服务已经启动成功。
MySQL使用:
关于连接 文件夹【数据库】 文件【表】 数据行【行】 数据行 数据行 连接: 默认:用户root show databases; use 数据库名称; show tables; select * from 表名; select name,age,id from 表名; mysql数据库user表 use mysql; select user,host from user; 创建用户: create user 'alex'@'192.168.1.1' identified by '123123'; create user 'alex'@'192.168.1.%' identified by '123123'; create user 'alex'@'%' identified by '123123'; 授权: 权限 人 grant select,insert,update on db1.t1 to 'alex'@'%'; grant all privileges on db1.t1 to 'alex'@'%'; revoke all privileges on db1.t1 from 'alex'@'%'; DBA: 用户名密码 2. 学习SQL语句规则 操作文件夹 create database db2; create database db2 default charset utf8; ***** show databases; drop database db2; 操作文件 show tables; create table t1(id int,name char(10)) default charset=utf8; create table t1(id int,name char(10))engine=innodb default charset=utf8; create table t3(id int auto_increment,name char(10))engine=innodb default charset=utf8; ***** create table t1( 列名 类型 null, 列名 类型 not null, 列名 类型 not null auto_increment primary key, id int, name char(10) )engine=innodb default charset=utf8; # innodb 支持事务,原子性操作 # myisam myisam auto_increment 表示:自增 primary key: 表示 约束(不能重复且不能为空); 加速查找 not null: 是否为空 数据类型: 数字: tinyint int bigint FLOAT 0.00000100000123000123001230123 DOUBLE 0.00000000000000000000100000123000123001230123 0.00000100000123000000000000000 decimal 0.1 字符串: char(10) 速度快() root root varchar(10) 节省空间 root PS: 创建数据表定长列往前放 text 上传文件: 文件存硬盘 db存路径 时间类型 DATETIME enum set create table t1( id int signed not null auto_increment primary key, num decimal(10,5), name char(10) )engine=innodb default charset=utf8; 清空表: delete from t1; truncate table t1; 删除表: drop table t1; 操作文件中内容 插入数据: insert into t1(id,name) values(1,'alex'); 删除: delete from t1 where id<6 修改: update t1 set age=18; update t1 set age=18 where age=17; 查看数据: select * from t1; 外键: create table userinfo( uid int auto_increment primary key, name varchar(32), department_id int, xx_id int, constraint fk_user_depar foreign key (department_id) references color(id) )engine=innodb default charset=utf8; create table department( id bigint auto_increment primary key, title char(15) )engine=innodb default charset=utf8; innodb原子操作