mysql 8 带来了全新的体验,比如支持 nosql、json 等,拥有比 mysql 5.7 两倍以上的性能提升。本文讲解如何在 windows 下安装 mysql 8,以及基本的 mysql 用法。
下载
本例为:mysql community server 8.0.12。
解压
解压至安装目录,比如 d 盘根目录下。
本例为:d:\mysql-8.0.12-winx64。
创建 my.ini
my.ini 是 mysql 安装的配置文件:
[mysqld] # 安装目录 basedir=d:\\mysql-8.0.12-winx64 # 数据存放目录 datadir=d:\\mysqldata\\data
my.ini放置在 mysql 安装目录的根目录下。需要注意的是,要先创建d:\mysqldata目录。data目录是由 mysql 来创建。
初始化安装
执行:
mysqld --defaults-file=d:\mysql-8.0.12-winx64\my.ini --initialize --console
控制台输出如下,说明安装成功:
>mysqld --defaults-file=d:\mysql-8.0.12-winx64\my.ini --initialize --console 2018-08-20t16:14:45.287448z 0 [system] [my-013169] [server] d:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 5012 2018-08-20t16:14:45.289628z 0 [error] [my-010457] [server] --initialize specified but the data directory has files in it. aborting. 2018-08-20t16:14:45.299329z 0 [error] [my-010119] [server] aborting 2018-08-20t16:14:45.301316z 0 [system] [my-010910] [server] d:\mysql-8.0.12-winx64\bin\mysqld.exe: shutdown complete (mysqld 8.0.12) mysql community server - gpl. d:\mysql-8.0.12-winx64\bin>mysqld --defaults-file=d:\mysql-8.0.12-winx64\my.ini --initialize --console 2018-08-20t16:15:25.729771z 0 [system] [my-013169] [server] d:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 18148 2018-08-20t16:15:43.569562z 5 [note] [my-010454] [server] a temporary password is generated for root@localhost: l-hk!rbuk9-. 2018-08-20t16:15:55.811470z 0 [system] [my-013170] [server] d:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server has completed
其中,“l-hk!rbuk9-.”就是 root 用户的初始化密码。稍后可以做更改。
启动、关闭 mysql server
执行mysqld就能启动 mysql server,或者执行 mysqld –console可以看到完整的启动信息:
>mysqld --console 2018-08-20t16:18:23.698153z 0 [warning] [my-010915] [server] 'no_zero_date', 'no_zero_in_date' and 'error_for_division_by_zero' sql modes should be used with strict mode. they will be merged with strict mode in a future release. 2018-08-20t16:18:23.698248z 0 [system] [my-010116] [server] d:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) starting as process 16304 2018-08-20t16:18:27.624422z 0 [warning] [my-010068] [server] ca certificate ca.pem is self signed. 2018-08-20t16:18:27.793310z 0 [system] [my-010931] [server] d:\mysql-8.0.12-winx64\bin\mysqld.exe: ready for connections. version: '8.0.12' socket: '' port: 3306 mysql community server - gpl.
关闭,可以执行 mysqladmin -u root shutdown。
使用 mysql 客户端
使用 mysql 来登录,账号为 root,密码为“l-hk!rbuk9-.”:
>mysql -u root -p enter password: ************ welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 11 server version: 8.0.12 copyright (c) 2000, 2018, oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or its affiliates. other names may be trademarks of their respective owners. type 'help;' or '\h' for help. type '\c' to clear the current input statement.
执行下面的语句来改密码。其中“123456”即为新密码。
mysql> alter user 'root'@'localhost' identified by '123456'; query ok, 0 rows affected (0.13 sec)
mysql 常用指令
显示已有的数据库:
mysql> show databases; +--------------------+ | database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.08 sec)
创建新的数据库:
mysql> create database lite; query ok, 1 row affected (0.19 sec)
使用数据库:
mysql> use lite; database changed
建表:
建表执行:
mysql> create table t_user (user_id bigint not null, username varchar(20)); query ok, 0 rows affected (0.82 sec)
查看表:
查看数据库中的所有表:
mysql> show tables; +----------------+ | tables_in_lite | +----------------+ | t_user | +----------------+ 1 row in set (0.00 sec)
查看表的详情:
mysql> describe t_user; +----------+-------------+------+-----+---------+-------+ | field | type | null | key | default | extra | +----------+-------------+------+-----+---------+-------+ | user_id | bigint(20) | no | | null | | | username | varchar(20) | yes | | null | | +----------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
插入数据:
mysql> insert into t_user(user_id, username) values(1, '老卫'); query ok, 1 row affected (0.08 sec)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
MySQL-关系代数-并、交、差、等值连接、自然连接、左连接。。。
【MySQL牛客】10.获取所有非manager的员工emp_no
网友评论