zoukankan      html  css  js  c++  java
  • windows安装mysql

    MySQL介绍

    MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司。MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。

    mysql是什么

    mysql就是一个基于socket编写的C/S架构的软件
    
    客户端软件
      mysql自带:如mysql命令,mysqldump命令等
      python模块:如pymysql
    

    数据库管理软件分类

    分两大类:
      关系型:如sqllite,db2,oracle,access,sql server,MySQL,注意:sql语句通用
      非关系型:mongodb,redis,memcache
    
    可以简单的理解为:
        关系型数据库需要有表结构
        非关系型数据库是key-value存储的,没有表结构

    下载

    访问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服务

    tasklist |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:Windowssystem32>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:Windowssystem32>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:Windowssystem32>mysqladmin -u root -p password "123" #修改密码123
    Enter password:
    Warning: Using a password on the command line interface can be insecure.
    
    C:Windowssystem32>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:Windowssystem32>mysqladmin -u root -p123 password "456"  #修改密码为456
    Warning: Using a password on the command line interface can be insecure.
    
    C:Windowssystem32>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:pythonStudymysql5.6
    #data目录
    datadir=C:pythonStudymysql5.6data #在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字符

  • 相关阅读:
    SQL Server 各版本安装包分享
    你真的了解数据库工程师吗?写给想从事数据库方面工作的朋友
    SQL Server中CASE WHEN的用法
    SQL Server存储过程用法介绍
    python---re模块
    python----openpyxl模块
    selenium(一)---selenium基础
    数据库---MySQL(三)
    数据库---MySql(二)-pymysql
    数据库---MySQL(一)
  • 原文地址:https://www.cnblogs.com/xiao-apple36/p/9521195.html
Copyright © 2011-2022 走看看