# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
# service mysqld stop //停止服務
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking& //在安全模式下執行
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('輸入新密碼')where USER='root';
Query OK, 0 rows affected (0.01 sec)
Rows matched: 3 Changed: 0 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
# mysql -u root -p
Enter password:
mysql>
重置MySQL管理者密碼
忘記root密碼怎麼辦?以下的方法幫你重新設定密碼。
問卷系統LimeSurvey
最近同事為了教育部問卷系統要暫時停擺的問題而傷透腦筋,本來建議他向計資中心求助,但得到的回應卻大失所望,所以只好親自出馬,LimeSurvey是功能強大的問卷系統,有Windows和Linux版本。
相關資料來源:
LimeSurvey官網
系統需求
LimeSurvey載點
安裝 FAQ
使用phpMyAdmin去搜尋參數值shownoanswer,並將他改為0,就不會出現了。
相關資料來源:
LimeSurvey官網
系統需求
LimeSurvey載點
安裝 FAQ
安裝步驟
- 安裝必要套件及相關模組
- 初始化MySQL資料庫
- 安裝LimeSurvey
# yum install -y httpd php mysql mysql-server phpMyAdmin //phpMyAdmin來源為EPEL,repo檔請至EPEL官網下載安裝。
# yum install -y php-mbstring php-mysql // Multibyte String Functions及PDO database driver for MySQL模組
# service httpd start
# chkconfig httpd on
# service httpd restart
# vim /var/www/html/info.php
<?php
phpinfo();
?>
# chkconfig mysqld on
# service mysqld start
# mysqladmin -u root password 12345
# /usr/bin/mysql_secure_installation
Enter current password for root (enter for none): 12345
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
產生一個新的資料庫給LimeSurvey使用,可以用指令,也可以用phpMyAdmin。
# mysql -u root -p
Enter password:
mysqld>CREATE DATABASE cc_survey;
Query OK, 1 row affected (0.00 sec)
mysqld>quit
# wget http://www.limesurvey.org/en/stable-release/finish/25-latest-stable-release/900-limesurvey200plus-build130708.tar.gz
# tar zxvf limesurvey200plus-build130708.tar.gz
# cp -r limesurvey/* /var/www/html/
進入設定頁面時發生錯誤,因為無寫入權限
# chmod -R 777 /var/www/html/tmp
最低要求並未完全滿足
# chmod 777 /var/www/html/application/config/
# chmod -R 777 /var/www/html/upload/
可選擇性模組還有三個未安裝:既然是可選擇性,也就是說可以不安裝就進行下一步,但還是裝一下吧!
# yum list | grep --color -Ew 'php-|gd|ldap|imap'
php-gd
php-ldap
php-imap
# yum install -y php-gd php-ldap php-imap
# service httpd restart
這樣是不是好看多了!
設定資料庫:欄位(資料庫名稱)就是前面資料庫設定時所新增的cc_survey
管理端網址:http://you.domainname.com/index.php/admin/authentication/sa/login
Q&A
當你將某一個問題的"必須回應"設定為否時,該問題在問卷畫面上會自動多出一個"不想回答"的選項,而進入所有的頁面都找不到如何讓他消失的設定,這該如何解決呢?使用phpMyAdmin去搜尋參數值shownoanswer,並將他改為0,就不會出現了。
備份MySQL資料庫II-自動備份的Script
Script 的撰寫
# vim /root/mysql-backup.sh
#!/bin/bash
YMD=$(date +%Y-%m-%d)
YMD180=$(date +%Y-%m-%d --date -180days)
basedir="/var/www/mysqlbackup"
#備份當月資料庫
/usr/bin/mysqldump -u root -pQUpM6EaQHMaaEJnu --all-database > "$basedir"/"$YMD".ccdb.sql
#刪除半年以前的備份
/bin/rm -rf "$basedir"/"$YMD180".ccdb.sql
#備份至 NAS 空間
/usr/bin/rsync -av --progress --delete --port=873 --password-file=/etc/rsyncd.secrets "$basedir"/ admin@192.168.xxx.xxx::mysqlbackup // /etc/rsyncd.secrets 的內容是連到 NAS 的管理者密碼
export LANG=zh_TW.UTF-8
mail -s "網頁伺服器維護通知信" root@localhost < /root/backuplog.txt // 維護通知信的內容
# vim /root/backuplog.txt
每月1日早上6點進行資料庫備份作業,保留半年內的備份。
已完成MySQL資料庫自動備份作業
已完成MySQL資料庫備份檔上傳NAS作業(\\backupserver\mysqlbackup)
註:192.168.xxx.xxx::mysqlbackup是NAS路徑。自動排程:每月1日早上6點進行資料庫備份作業
# crontab -e
0 6 1 * * /root/mysql-backup.sh
備份MySQL資料庫I-基本資料庫操作
考完 RHCE 後偷懶了一段時間,該是回來的時候了。
因為工作的需要,曾經寫了網頁伺服器自動份備的 Script,目前因為要備份資料庫,又有新內容要產出了。
所以實戰還是最容易增進實力的方法。
安裝 Mysql 相關套件、啟動服務並進行設定
# yum install -y mysql mysql-server
# chkconfig mysqld on
# service mysqld start
# mysqladmin -u root password 12345 // 參考補充
# /usr/bin/mysql_secure_installation // 參考補充
# mysql -u root -p databse_name // -p 代表登入使用者有密碼保護
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, 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>show databases;
+--------------------+
| Database
+--------------------+
| information_schema
| mysql
+--------------------+
2 rows in set (0.00 sec)
mysql>create database backup_test; // 新增一個資料庫;刪除的指令drop database backup_test;
mysql>show databases;
+--------------------+
| Database
+--------------------+
| information_schema
| backup_test
| mysql
+--------------------+
2 rows in set (0.00 sec)
備份所有資料庫:連帳號也會一併備份
# mysqldump -u root -p --all-databases > /root/test.sql
匯入所有資料庫
# mysql -u root -p < /root/test.sql
補充:第一次啟動 MySql 時的狀態,會提醒使用者接下來要執行什麼指令。
# service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]















