zoukankan      html  css  js  c++  java
  • MySQL环境部署

    阅读目录:

    1、Windows下安装MySQL

    2、Linux下安装MySQL

    序章:

    MySQL是个小型的数据库,用来自己做小项目,做学习练习什么的再适合不过了,不过新手总会被一些莫名奇妙的问题难住,想要学习什么的,连环境都搭不好,简直是受罪,我也是个饱受这种痛苦的新手,所以想把遇到的问题都总结下来,以后再碰到,不用到处去找资料。

    新手在Windows环境下,建议下载Installer MSI版本的,安装简单直接Next…直到Finish…完成安装,虽然只有32位的,但是作为学习练习,还是够用了(比如学习Java、Python、C#、SQL等语言),可不能输在搭建环境上,对吧!

    但是还是有很多像我这样的强迫症患者,用了64位的操作系统,非要下64位的zip版本的MySQL心里才舒服。

    MySQL下载地址:http://dev.mysql.com/downloads/mysql/

    1、Windows下安装MySQL

    我下的是最新版的MySQL,解压后,目录如下:

    image

    可以看到上图,MySQL5.7它没有data目录,如果没有data目录,安装后启动的时候就会报这个错:

    复制代码
    D:Servicemysql57in>net start mysql
    MySQL 服务正在启动 .
    MySQL 服务无法启动。
    

    服务没有报告任何错误。

    请键入 NET HELPMSG 3534 以获得更多的帮助。

    复制代码

    为了避免这个错误,需要使用命令生成data文件夹,按如下步骤安装

    1. 进入dos的命令行,一定要用administrator进入。

    image

    2. 进入MySQL的bin目录,输入mysqld –install可以安装MySQL

    复制代码
    D:>cd D:Servicemysql57in
    

    D:Servicemysql57in>mysqld -install
    Service successfully installed.

    复制代码

    3. 输入以下命令,可以初始化MySQL数据库,初始化了之后,会打印出MySQL的默认生成的密码,下面标红了的就是默认生成的密码。

    复制代码
    D:Servicemysql57in>mysqld --initialize --user=root --console
    2015-12-20T08:13:45.264865Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2015-12-20T08:13:45.854579Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2015-12-20T08:13:45.998772Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2015-12-20T08:13:46.098118Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9755c3ea-a6f1-11e5-81a3-74d02b122fb3.
    2015-12-20T08:13:46.121617Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2015-12-20T08:13:46.135153Z 1 [Note] A temporary password is generated for root@localhost: g!gRw!d%M0Sj
    复制代码

    初始化了以后,可以看到MySQL目录下,多了data目录

    image

    4. 启动MySQL服务

    D:Servicemysql57in>net start mysql
    MySQL 服务正在启动 .
    MySQL 服务已经启动成功。

    5. 使用默认生成的密码,进入mysql

    复制代码
    D:Servicemysql57in>mysql -u root -p
    Enter password: ************
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 4
    Server version: 5.7.10
    

    Copyright (c) 2000, 2015, 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>

    复制代码

    6. 进入了mysql就可以修改默认密码了(我把默认密码修改成了root)

    mysql> set password = password('root') ;

    这个时候,Windows下的MySQL环境就已经安装好了。

    2、Linux下安装MySQL

    如果有网络的话,Linux下安装就简单多了,我这用的CentOS安装的

    1. 安装MySQL服务,下面用yum安装,它会自动安装需要的依赖包,很方便,但是要用root用户来安装

    [root@bogon ~]# yum install mysql-server

    2. 启动MySQL服务,第一次启动服务会有点慢

    [root@bogon ~]# /etc/init.d/mysqld restart

    3. 启动了MySQL服务,就可以使用ps命令,可以查看到MySQL这个服务,说明服务已经启动了

    复制代码
    [root@bogon ~]# ps -ef | grep mysql
    root       3474      1  0 22:29 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
    mysql      3576   3474  0 22:29 pts/0    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
    root       3614   3334  0 22:34 pts/0    00:00:00 grep mysql
    复制代码

    4. 直接输入mysql就可以进入MySQL了

    复制代码
    [root@bogon ~]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.1.73 Source distribution
    

    Copyright (c) 2000, 2013, 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>

    复制代码

    5. 设置MySQL的密码,我这边设置密码为root,以后就可以用这个密码来登录MySQL了

    mysql> set password = password('root');
    Query OK, 0 rows affected (0.00 sec)
  • 相关阅读:
    知识【inline】
    .net实现文件或目录复制到指定目录 及 压缩
    asp实现页面打印功能
    C#创建Windows服务(附服务安装)
    导出合并行及合并列
    Abp添加DBContext
    Background Jobs 调用接口时间长解决
    DataTable去掉空行
    Maven配置
    二维码q
  • 原文地址:https://www.cnblogs.com/R-bear/p/15048858.html
Copyright © 2011-2022 走看看