閱讀目錄:
一、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)