新增 mysql 使用者:
[root@www ~]# groupadd mysql
[root@www ~]# useradd -s /sbin/nologin -g mysql -m mysql
-s /sbin/nologin 表示禁止該使用者登入系統,提高安全性
-g mysql 指定mysql 使用者屬於mysql組
-m 表示不建立使用者家目錄(這裡沒必要建立)
檢查剛剛建立的mysql使用者和組:
[root@www ~]# tail -1 /etc/passwd
mysql:x:501:501::/home/mysql:/sbin/nologin
[root@www ~]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
獲取mysql軟體包:
在mysql官網 選linux - generic本文用的包是 mysql-5.5.49-linux2.6-x86_64.tar.gz
平台是 centos6.4
5.5版本的mysql,空密碼,可直接登入
[root@www ~]# wget
6_64.tar.gz # 獲取mysql軟體壓縮包
[root@www ~]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz # 解壓
# 移動到指定的安裝目錄,目錄標明了mysql的版本( 二進位制安裝可以自定義安裝目錄 )
# 建立軟鏈結
[root@www mysql]# ls
bin data include lib mysql-test scripts sql-bench
copying docs install-binary man readme share support-files
初始化 mysql 配置檔案 my.cnf:
在support-file 下有 my.cnf 的各種配置樣例,根據情況選擇配置檔案。[root@www mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
# 授權mysql使用者管理mysql的安裝目錄
> --user=mysql # 指定使用者
# 初始化成功會有2個 ok ,如果有error 錯誤,就要去解決,再初始化
注意:有些軟體包的 mysql_install_db 不在 scripts 目錄下 ,可能在 bin目錄下或其他目錄下
配置並啟動 mysql 資料庫:[root@www mysql]# cp support-files/mysql.server /etc/init.d/mysqld
# 拷貝 mysql啟動指令碼到mysql 的命令路徑
[root@www mysql]# chmod +x /etc/init.d/mysqld # 新增執行許可權
# mysql 二進位制預設安裝路徑是/usr/local/mysql,啟動指令碼裡是/usr/local/mysql的路徑都需要替換
[root@www mysql]# /etc/init.d/mysqld start
starting mysql... success!
設定mysql開機自動啟動:[root@www mysql]# chkconfig --add mysqld
[root@www mysql]# chkconfig mysqld on
[root@www mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 2
server version: 5.5.49 mysql community server (gpl)
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>
[root@www mysql]# source /etc/profile
# 使追加內容的生效
# 以上用途為定義mysql全域性路徑,實現在任意路徑執行mysql命令
[root@www ~]# mysql # 直接進入mysql
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 3
server version: 5.5.49 mysql community server (gpl)
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>
[root@www ~]# mysql -uroot -p # 也可這樣登入,不需要使用密碼
設定 mysql 的 root密碼:[root@www mysql]# mysqladmin -u root password 'redhat'
[root@www mysql]# mysql
error 1045 (28000): access denied for user 'root'@'localhost' (using password: no)
[root@localhost mysql]# mysql -uroot -p
enter password:
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 6
server version: 5.5.49 mysql community server (gpl)
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>
學習之路 MySQL(2)
看完上篇部落格之後,應該mysql的開發環境都配置好了,現在入正題,學習下mysql的用法 一 mysql的語句規範 1 關鍵字與函式名稱是要全部大寫的,例如 show alter 2 資料名稱,欄位名稱,表名稱是要全部小寫的 3 sql語句必須以英文分號 結尾 二 對資料進行操作 通俗的說,就是找...
MySQL(2) 關聯對映
1.多表的關係,一對一,一對多,多對多 2.實現關聯的方法 3.以mysql舉例 建立country表 主鍵是name 建立presidengt表 主鍵是name 對應關係 乙個國家對應乙個 乙個 對應乙個國家。country表中的name對應president表中的f country name。指...
mysql(2)許可權管理
1.初始化完成之後的使用者 只有乙個root使用者,5.6及之前的版本是沒有密碼的,5.7會產生隨機密碼,在初始化時可以看到,在配置日誌檔案中也可以檢視。2.使用者的許可權管理步驟 1 檢查使用者的 hip和使用者名稱是否被允許 2 檢視mysql.user表是否存在該使用者,這裡沒有許可權設定,預...