阅读目录:
一、Windows下安装MySQL
二、Linux下安装MySQL
序章:
MySQL是个小型的数据库,用来本身作小项目,作学习练习什么的再适合不过了,不过新手总会被一些莫名奇妙的问题难住,想要学习什么的,连环境都搭很差,简直是受罪,我也是个饱受这种痛苦的新手,因此想把遇到的问题都总结下来,之后再碰到,不用处处去找资料。
新手在Windows环境下,建议下载Installer MSI版本的,安装简单直接Next…直到Finish…完成安装,虽然只有32位的,可是做为学习练习,仍是够用了(好比学习Java、Python、C#、SQL等语言),可不能输在搭建环境上,对吧!
可是仍是有不少像我这样的强迫症患者,用了64位的操做系统,非要下64位的zip版本的MySQL内心才舒服。
MySQL下载地址:http://dev.mysql.com/downloads/mysql/
一、Windows下安装MySQL
我下的是最新版的MySQL,解压后,目录以下:
能够看到上图,MySQL5.7它没有data目录,若是没有data目录,安装后启动的时候就会报这个错:
D:\Service\mysql57\bin>net start mysqlMySQL 服务正在启动 .MySQL 服务没法启动。服务没有报告任何错误。请键入 NET HELPMSG 3534 以得到更多的帮助。
为了不这个错误,须要使用命令生成data文件夹,按以下步骤安装mysql
D:\>cd D:\Service\mysql57\binD:\Service\mysql57\bin>mysqld -installService successfully installed.
D:\Service\mysql57\bin>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=457902015-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 thisis 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目录
sql
D:\Service\mysql57\bin>net start mysqlMySQL 服务正在启动 .MySQL 服务已经启动成功。
D:\Service\mysql57\bin>mysql -u root -pEnter password: ************Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is4Server version: 5.7.10Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.mysql>
mysql> set password = password('root') ;
这个时候,Windows下的MySQL环境就已经安装好了。
二、Linux下安装MySQL
若是有网络的话,Linux下安装就简单多了,我这用的CentOS安装的数据库
[root@bogon ~]# yum install mysql-server
[root@bogon ~]# /etc/init.d/mysqld restart
[root@bogon ~]# ps -ef | grep mysqlroot 34741022:29 pts/000: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=mysqlmysql 35763474022:29 pts/000: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.sockroot 36143334022:34 pts/000:00:00 grep mysql
[root@bogon ~]# mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is3Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.mysql>
mysql> set password = password('root');Query OK, 0 rows affected (0.00 sec)