上一節我主要記錄了樹莓派的啟動使用,這一節主要記錄下在樹莓派上面安裝mysql,因為我要在上面運行NLifeBill所以我就先安裝mysql。
首先我想啟用root用戶,所以我先啟用root用戶:
sudo passwd root
這里會提示輸入兩次密碼,然后:
sudo passwd --unlock root
這樣就可以啟動root登錄,如果想立馬使用root,可以:
su root
這樣就可以直接切換到root用戶不過會提示輸入密碼,如果下次用root登錄的話就會在登錄的時候顯示設置畫面,如果你只是玩玩就可以不用管這個。
接下來要安裝mysql,安裝之前可以先更新下本機軟件:
sudo apt-get update
然后就是等待了。等待完之后要准備安裝mysql了,命令直接安裝:
sudo apt-get install mysql-server
然后就是等待,在安裝的過程中會提示你讓你輸入mysql的root密碼,會提示兩次。輸入完成之后就會安裝成功了。
然后輸入如下命令進入mysql:
mysql -u root -p
然后會提示輸入密碼,輸入密碼就可以進入mysql:
1 root@raspberrypi:/home/pi# mysql -u root -p 2 Enter password: 3 Welcome to the MySQL monitor. Commands end with ; or \g. 4 Your MySQL connection id is 43 5 Server version: 5.5.35-0+wheezy1 (Debian) 6 7 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 8 9 Oracle is a registered trademark of Oracle Corporation and/or its 10 affiliates. Other names may be trademarks of their respective 11 owners. 12 13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 14 15 mysql>
然后創建我要使用的數據庫LifeBill:
1 mysql> create database lifebill 2 -> ; 3 Query OK, 1 row affected (0.01 sec)
數據庫創建好之后要新建個用戶:
1 mysql> create user dn9x identified by "123"; 2 Query OK, 0 rows affected (0.00 sec)
新用戶創建完成之后要授權給他,這里我只是授權了只能本機登錄:
mysql> grant insert, delete, update, select on lifebill.* to dn9x@localhost identified by "123"; Query OK, 0 rows affected (0.00 sec)
授權完成之后用新用戶登錄下看看數據庫:
1 mysql> show databases; 2 +--------------------+ 3 | Database | 4 +--------------------+ 5 | information_schema | 6 | lifebill | 7 +--------------------+ 8 2 rows in set (0.00 sec)
顯示lifebill已經在此用戶下了,接下來就是要導入基本數據了,這里我的數據和項目都放在github上面,所以先把項目down下來,而Raspbian有安裝好的git,這樣就好辦多了。
1 git clone https://github.com/Dn9x/NLifeBill
因為我的sql文件也在項目里面,項目也是要用的,所以就直接down下整個項目。然后導入sql數據:
1 mysql -u root -p -D lifebill</home/pi/github/NLifeBill/db/lifebill.sql
到此數據就導入成功了!查詢下表和數據都沒有問題,接下來就是NodeJs方面的問題了!