码迷,mamicode.com
首页 > 数据库 > 详细

windows安装mysql

时间:2018-08-23 02:10:37      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:load   ace   monit   中文   users   文件   密码登录   ODB   密码   

下载

访问https://dev.mysql.com/downloads/mysql/下载mysql5.6

技术分享图片

下载后解压缩,看到如下目录

技术分享图片

 

安装启动mysql

1.添加环境变量
【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【将MySQL的bin目录路径追加到变值值中,用 ; 分割】
技术分享图片

2.初始化
mysqld --initialize-insecure

3.启动MySQL服务
mysqld # 启动MySQL服务

4.启动MySQL客户端并连接MySQL服务
mysql -u root -p # 连接MySQL服务器

打开一个终端输出mysqld启动服务,另一个终端输入mysql访问mysql,出现界面mysql > 说明启动mysql成功

技术分享图片

 

5.查看mysql服务

takslist |findstr mysql

技术分享图片

 

 

将MySQL服务制作成windows服务

注意:--install前,必须用mysql启动命令的绝对路径
# 制作MySQL的Windows服务,在终端执行此命令:

mysqld --install

# 移除MySQL的Windows服务,在终端执行此命令:

mysqld --remove

注册成服务之后,以后再启动和关闭MySQL服务时,仅需执行如下命令:
# 启动MySQL服务
net start mysql

# 关闭MySQL服务
net stop mysql

 用管理员cmd输入命令

 技术分享图片

 

杀掉mysql进程,启动服务

技术分享图片

 

启动与停止mysql服务

技术分享图片

 

 

登录设置密码

C:\Windows\system32>mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 MySQL Community Server (GPL)

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.

mysql>
mysql>
mysql> select user(); # 查看用户
+----------------+
| user()         |
+----------------+
| ODBC@localhost |
+----------------+
1 row in set (0.00 sec)

mysql> exit
Bye

C:\Windows\system32>mysql -u root -p #使用root用户登录,默认密码为空
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 MySQL Community Server (GPL)

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.

mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql> exit
Bye

C:\Windows\system32>mysqladmin -u root -p password "123" #修改密码123
Enter password:
Warning: Using a password on the command line interface can be insecure.

C:\Windows\system32>mysql -u root -p  #用密码123登录数据库
Enter password: ***
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.41 MySQL Community Server (GPL)

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.

mysql> exit
Bye


C:\Windows\system32>mysqladmin -u root -p123 password "456"  #修改密码为456
Warning: Using a password on the command line interface can be insecure.

C:\Windows\system32>mysql -uroot -p456 #用密码456登录数据库
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.41 MySQL Community Server (GPL)

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.

mysql> select user()
    -> ;
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

  

破解密码

#1 关闭mysql
#2 在cmd中执行:mysqld --skip-grant-tables
#3 在cmd中执行:mysql
#4 执行如下sql:
update mysql.user set authentication_string=password(‘‘) where user = ‘root‘;
flush privileges;

#5 tskill mysqld #或taskkill -f /PID 进程号
#6 重新启动mysql

 

 停止mysql服务,跳过授权方式启动

技术分享图片

 

修改mysql服务器root密码

C:\Users\>mysql -uroot -p              #使用空密码登录
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 MySQL Community Server (GPL)

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.

mysql> select user();
+--------+
| user() |
+--------+
| root@  |
+--------+
1 row in set (0.00 sec)

mysql> update mysql.user set password=password("111") where user="root" and host="localhost"; #修改密码
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;               #刷新权限
Query OK, 0 rows affected (0.03 sec)

mysql> exit
Bye

  

重启mysql服务器,使用新密码111登录

技术分享图片

 

统一字符编码

强调:配置文件中的注释可以有中文,但是配置项中不能出现中文

#在mysql的解压目录下,新建my.ini,然后配置
#1. 在执行mysqld命令时,下列配置会生效,即mysql服务启动时生效
[mysqld]
;skip-grant-tables
port=3306
character_set_server=utf8
default-storage-engine=innodb
innodb_file_per_table=1


#解压的目录
basedir=C:\pythonStudy\mysql5.6
#data目录
datadir=C:\pythonStudy\mysql5.6\data\ #在mysqld --initialize时,就会将初始数据存入此处指定的目录,在初始化之后,启动mysql时,就会去这个目录里找数据



#2. 针对客户端命令的全局配置,当mysql客户端命令执行时,下列配置生效
[client]
port=3306
default-character-set=utf8
user=root
password=111

#3. 只针对mysql这个客户端的配置,2中的是全局配置,而此处的则是只针对mysql这个命令的局部配置
[mysql]
;port=3306
;default-character-set=utf8
user=egon
password=4573

 my.ini字符编码设置 

#1. 修改配置文件
[mysqld]
default-character-set=utf8 
[client]
default-character-set=utf8 
[mysql]
default-character-set=utf8

#mysql5.5以上:修改方式有所改动
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

#2. 重启服务
#3. 查看修改结果:
\s
show variables like ‘%char%‘

 

技术分享图片

 

  

 技术分享图片

 

windows mysql默认安装字符

技术分享图片

 

  修改mysql字符后,重启查看新设置的utf-8字符

技术分享图片

 

 

技术分享图片

 

windows安装mysql

标签:load   ace   monit   中文   users   文件   密码登录   ODB   密码   

原文地址:https://www.cnblogs.com/xiao-apple36/p/9521195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!