博文目錄: 1.Mysql-5.0.40.tar.gz Mysql-5.1.72.tar.gz 2.Mysql-5.5.22.tar.gz 3.Mysql-5.5.34.tar.gz 4.Mysql-5.6.36tar.gz
附: 1.賬號安全
|
-----------MySQL 5.0以后版本的安裝-----------
MySQL安裝
安裝包學習的必殺絕技——就是閱讀包的安裝說明(readme & install)文檔。
----------
# rm /etc/my.cnf ? ? ? ? ? ?(安裝前執行一下)
----------
1.Mysql-5.0.40.tar.gz
1.1.Source Installation Overview(lines 74 of install-source)
系統默認可能會安裝三個mysql的包: mysql-libs mysql mysql-devel 從下往上依賴關系。 |
源碼包安裝mysql
檢查環境
Shell>?rpm?-aq?|?grep?mysql
Shell>?rpm?-ql?mysql
Shell>?rpm?-qf?/etc/my.conf
Shell>?rpm?-qc?mysql-libs
Shell>?rpm?-qR?mysql-libs
Shell>?rpm?-qd?mysql
Shell>?rpm?-qi?mysql
Shell>?netstat?-nlt
Shell>?find?/?-name?mysql
Shell>?find?/?-name?my.conf
Shell>?cat?/etc/passwd?|?grep?mysql
Shell>?cat?/etc/group?|
Shell>?rpm?-qa?|?grep?gcc
Shell>?rpm?-qa?|?grep?make
Shell>?ls?/home添加用戶
Shell>?groupadd?-r?mysql
Shell>?useradd?-g?mysql?-M?-r?-s?/sbin/nologin?mysql開始安裝
Shell>?vi?INSTALL-SOURCE
Shell>?./configure?--prefix=/usr/local/mysql
Shell>?echo?$?
Shell>?make
Shell>?echo?$?
Shell>?make?install
Shell>?echo?$?配置文件
Shell>?cp?support-files/my-medium.cnf?/etc/my.conf
目錄權限
Shell>?cd?/usr/local/mysql
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
初始化數據庫
Shell>?bin/mysql_install_db?--user=mysql
開機啟動
Shell>?cp?/support-files/mysql.server?/etc/init.d/mysqld
Shell>?chmod?755?/etc/init.d/mysqld
安全啟動服務/把數據庫的數據文件定義到其他磁盤設備上
Shell>?bin/mysqld_safe?--user=mysql?--datadir=/dell/mysql_data
1.2.Typical ‘configure’ Options(lines 265 of ?install-source)
配置
Shell>?./configure?--help
Shell>?./configure?-h僅僅編譯客戶端程序
Shell>?./configure?--without-server默認安裝的目錄/usr/local(數據目錄/usr/local/var)??梢愿膶憺?#xff1a;
Shell>?./configure?--prefix=/usr/local/mysql
Shell>?./configure?--prefix=/usr/local/?--localstatedir=/usr/local/mysql/data使用unix的套接字方式連接數據庫:
Shell>?./configure?--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock有gcc,沒有c++庫,可以使用gcc來作為c++的編譯器:
Shell>?CC=gcc?CXX=gcc?./configure
Shell>?./configure?--with-charset=gb2312
Shell>?./configure?--with-charset=utf8
Shell>?./configure?--with-charset=latin1(這個是默認值)
Shell>?./configure?--with-collation=latin1_swedish_ci(這個是排序方法的默認值)
Shell>?./configure?--with-extra-charsets=(空格分開)
Shell>?./configure?--with-extra-charsets=all重新編譯一個源碼樹時:
Shell>?rm?config.cache
Shell>?make?clean
Shell>?make?dist
_____________
Mysql-5.1.72.tar.gz
安裝方法跟上邊的大同小異。
_____________
2.Mysql-5.5.22.tar.gz
2.1.Installing MySQL from Generic Binaries on Unix/Linux
系統默認可能會安裝三個mysql的包: mysql-libs mysql mysql-devel 從下往上依賴關系。 |
二進制文件安裝mysql
檢查環境
Shell>?rpm?-aq?|?grep?mysql
Shell>?rpm?-ql?mysql
Shell>?rpm?-qf?/etc/my.conf
Shell>?rpm?-qc?mysql-libs
Shell>?rpm?-qR?mysql-libs
Shell>?rpm?-qd?mysql
Shell>?rpm?-qi?mysql
Shell>?netstat?-nlt
Shell>?find?/?-name?mysql
Shell>?find?/?-name?my.conf
Shell>?cat?/etc/passwd?|?grep?mysql
Shell>?cat?/etc/group?|
Shell>?rpm?-qa?|?grep?gcc
Shell>?rpm?-qa?|?grep?make
Shell>?ls?/home添加用戶
Shell>?groupadd?mysql
Shell>?useradd?-r?-g?mysql?-M?-s?/sbin/nologin?mysql開始安裝
Shell>?cd?/usr/local
Shell>?tar?-zxvf?……
Shell>?cd?mysql
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
初始化數據庫
Shell>?scripts/mysql_install_db?--user=mysql
Shell>?chown?-R?root?.
Shell>?chown?-R?mysql?data配置操作
Shell>?cp?support-files/my-medium.cnf??/etc/my.cnf
Shell>?cp?support-files/mysql.server??/etc/init.d/mysqld
Shell>?chmod?755?/etc/init.d/mysqld
啟動服務
Shell>?bin/mysqld_safe?--user=mysql?--datadir=/dell/mysql_data
2.2.Installing MySQL from Source
源碼包安裝mysql
檢查環境
Shell>?rpm?-aq?|?grep?mysql
Shell>?rpm?-ql?mysql
Shell>?rpm?-qf?/etc/my.conf
Shell>?rpm?-qc?mysql-libs
Shell>?rpm?-qR?mysql-libs
Shell>?rpm?-qd?mysql
Shell>?rpm?-qi?mysql
Shell>?netstat?-nlt
Shell>?find?/?-name?mysql
Shell>?find?/?-name?my.conf
Shell>?cat?/etc/passwd?|?grep?mysql
Shell>?cat?/etc/group?|
Shell>?rpm?-qa?|?grep?gcc
Shell>?rpm?-qa?|?grep?make
Shell>?ls?/home添加用戶
Shell>?groupadd?mysql
Shell>?useradd?-r?-g?mysql?-M?-s?/sbin/nologin?mysql配置、編譯
Shell>?ccmake?.(先進行交互式配置)
Shell>?cmake?.
Shell>?make
Shell>?make?install
Shell>?cd?/usr/local/mysql
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
初始化數據庫
Shell>?scripts/mysql_install_db?--user=mysql
Shell>?chown?-R?root?.
Shell>?chown?-R?mysql?data
Shell>?cp?support-files/my-medium.cnf??/etc/my.cnf
Shell>?cp?support-files/mysql.server??/etc/init.d/mysqld
Shell>?chmod?755?/etc/rc.d/init.d/mysqld
啟動服務
Shell>?bin/mysqld_safe?--user=mysql?--datadir=/dell/mysql_data
2.3.To list the configuration options,use one of the following.
Shell>?cmake?.?-L#?overview
Shell>?cmake?.?-LH#?overview?with?help?text
Shell>?cmake?.?-LAH#?all?params?with?help?text
Shell>?ccmake?.#?interactive?display
Shell>?make?clean
Shell>?rm?CMakeCache.txt
2.4.rpm
To?see?all?files?in?an?RPM?packet,run?a?command?like?this:
Shell>?rpm?-qpl?MySQL-server-VERSION.glibc23.i386.rpm
Shell>?rpm?-ivh?MySQL-server-VERSION.glibc23.i386.rpm
Shell>?rpm?-ivh?MySQL-client-VERSION.glibc23.i386.rpmStart?from?a?source?RPM,run:
Shell>?rpmbuild?--rebuild?--clean?MySQL-VERSION.src.rpm
2.5.安裝Cmake-2.8.12.tar.gz
Shell>?vi?Readme.txt
Shell>?./bootstrap
Shell>?make
Shell>?make?install
3.Mysql-5.5.34.tar.gz
3.1. Installing MySQL on Unix/Linux Using Generic Binaries
二進制包安裝mysql
檢查當前環境配置
Shell>?rpm?-aq?|?grep?mysql
Shell>?rpm?-ql?mysql
Shell>?rpm?-qf?/etc/my.conf
Shell>?rpm?-qc?mysql-libs
Shell>?rpm?-qR?mysql-libs
Shell>?rpm?-qd?mysql
Shell>?rpm?-qi?mysql
Shell>?netstat?-nlt
Shell>?find?/?-name?mysql
Shell>?find?/?-name?my.conf
Shell>?cat?/etc/passwd?|?grep?mysql
Shell>?cat?/etc/group?|
Shell>?rpm?-qa?|?grep?gcc
Shell>?rpm?-qa?|?grep?make添加用戶
Shell>?groupadd?mysql
Shell>?useradd?-r?-g?mysql?-M?-s?/sbin/nologin?mysql
Shell>?cd?/usr/local
開始安裝
Shell>?tar?-zxvf?……
Shell>?cd?mysql
設定目錄權限
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
初始化數據庫
Shell>?scripts/mysql_install_db?--user=mysql
設定庫文件目錄權限
Shell>?chown?-R?root?.
Shell>?chown?-R?mysql?data
添加配置文件
Shell>?cp?support-files/my-medium.cnf?/etc/my.cnf
Shell>?cp?support-files/mysql.server?/etc/init.d/mysqld
Shell>?chmod?755?/etc/init.d/mysqld
啟動服務
Shell>?bin/mysqld_safe?--user=mysql?--datadir=/dell/mysql_data
3.2.Installing MySQL Using a Standard Source Distribution
源碼包安裝mysql
Shell>?rpm?-aq?|?grep?mysql
Shell>?rpm?-ql?mysql
Shell>?rpm?-qf?/etc/my.conf
Shell>?rpm?-qc?mysql-libs
Shell>?rpm?-qR?mysql-libs
Shell>?rpm?-qd?mysql
Shell>?rpm?-qi?mysql
Shell>?netstat?-nlt
Shell>?find?/?-name?mysql
Shell>?find?/?-name?my.conf
Shell>?cat?/etc/passwd?|?grep?mysql
Shell>?cat?/etc/group?|
Shell>?rpm?-qa?|?grep?gcc
Shell>?rpm?-qa?|?grep?make
Shell>?ls?/homeShell>?groupadd?mysql
Shell>?useradd?-r?-g?mysql?-M?-s?/sbin/nologin?mysqlShell>?cd?mysql
Shell>?ccmake?.(沒有這一步也過去了)
Shell>?cmake?.
Shell>?make
Shell>?make?install
Shell>?cd?/usr/local/mysql
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
Shell>?scripts/mysql_install_db?--user=mysql
Shell>?chown?-R?root?.
Shell>?chown?-R?mysql?data
Shell>?cp?support-files/my-medium.cnf?/etc/my.cnf
Shell>?cp?support-files/mysql.server?/etc/init.d/mysqld
Shell>?chmod?755?/etc/init.d/mysqld
Shell>?bin/mysqld_safe?--user=mysql?--datadir=/dell/mysql_data
4.Mysql-5.6.36.tar.gz
二進制包安裝mysql
添加用戶
[root@tri?blog]#?groupadd?-g?51?mysql
[root@tri?blog]#?useradd?-r?-u?51?-g?51?-d?/data02/blog/mysql_data?-s?/sbin/nologin?mysql開始安裝
[root@tri?local]#?tar?-xf?/opt/data01/tars/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@tri?local]#?ln?-s?mysql-5.6.36-linux-glibc2.5-x86_64/?mysql
[root@tri?local]#?cd?mysql
[root@tri?mysql]#?chown?-R?mysql:mysql?.
[root@tri?mysql]#?scripts/mysql_install_db?--user=mysql
[root@tri?mysql]#?chown?-R?root?.
[root@tri?mysql]#?chown?-R?mysql?data/
標準啟動
[root@tri?mysql]#?bin/mysqld_safe?--user=mysql
直接啟動
[root@tri?mysql]#?bin/mysqld_safe?--user=mysql?--bind-address=127.0.0.1?--port?3333解包后查看文件,編譯時配置“-prefix=”
[root@tri?mysql]#?vi?docs/INFO_BIN
CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql
MYSQL_DATADIR:PATH=/usr/local/mysql/data添加啟動時打開服務
[root@tri?mysql]#?cp?support-files/mysql.server?/etc/init.d/mysql
打開上述文件(提示配置文件、主目錄、數據目錄)
[root@tri?mysql]#?vi?/etc/init.d/mysql
#?If?you?install?MySQL?on?some?other?places?than?/usr/local/mysql,?then?you
#?have?to?do?one?of?the?following?things?for?this?script?to?work:
#
#?-?Run?this?script?from?within?the?MySQL?installation?directory
#?-?Create?a?/etc/my.cnf?file?with?the?following?information:
#???[mysqld]
#???basedir=<path-to-mysql-installation-directory>
#?-?Add?the?above?to?any?other?configuration?file?(for?example?~/.my.ini)
#???and?copy?my_print_defaults?to?/usr/bin
#?-?Add?the?path?to?the?mysql-installation-directory?to?the?basedir?variable
#???below.
#
#?If?you?want?to?affect?other?MySQL?variables,?you?should?make?your?changes
#?in?the?/etc/my.cnf,?~/.my.cnf?or?other?MySQL?configuration?files.#?If?you?change?base?dir,?you?must?also?change?datadir.?These?may?get
#?overwritten?by?settings?in?the?MySQL?configuration?files.basedir=
datadir=
附:1.賬號安全
-----------MySQL 安裝完成后的帳號安全問題-----------
? ?問題描述
? ?剛安裝好的系統, root 默認密碼為空;默認空用戶(空密碼)也可以在本地登錄;
? ?查看系統中有那些賬戶:
無用戶名、密碼本地登錄
[work@tri?~]$?mysql
使用有用戶名的方式登錄
[work@tri?~]$?mysql?-u?root?-h?localhost
mysql>?select?host,user,password?from?mysql.user;
mysql>?select?host,user,password?from?mysql.user;
+-----------+------+----------+
|?host??????|?user?|?password?|
+-----------+------+----------+
|?localhost?|?root?|??????????|
|?tri???????|?root?|??????????|
|?127.0.0.1?|?root?|??????????|
|?::1???????|?root?|??????????|
|?localhost?|??????|??????????|
|?tri???????|??????|??????????|
+-----------+------+----------+
6?rows?in?set?(0.00?sec)
? ?顯示結果,表示有多個 root 用戶;有兩個 空用戶。沒有一個有密碼。
? ?這就需要為每一個用戶設定密碼;同樣需要為空用戶設定密碼,或者刪除。
? ?mysql.db 中的某些行,允許所有用戶(包括沒有密碼的空賬戶;anonymous)訪問測試數據庫或者其
? ?他以 “test_” 開頭的數據庫。(這個默認設置是為了測試的)
? ?-------
? ?修改 root 密碼
shell>?mysql?-u?root
mysql>?SET?PASSWORD?FOR?'root'@'localhost'?=?PASSWORD('newpwd');
mysql>?SET?PASSWORD?FOR?'root'@'127.0.0.1'?=?PASSWORD('newpwd');
mysql>?SET?PASSWORD?FOR?'root'@'host_name'?=?PASSWORD('newpwd');
mysql>?select?host,user,password?from?mysql.user;
?
shell>?mysql?-u?root
mysql>?UPDATE?mysql.user?SET?password?=?PASSWORD('newpwd)->?WHERE?user?=?'root';
(沒有這步,就得重啟后才能生效)
mysql>?FLUSH?PRIVILEGES;????????shell>?mysqladmin?-u?root?password?"newpwd"
shell>?mysqladmin?-u?root?-h?host_name?password?"newpwd"
mysqladmin?無法對127.0.0.1起作用。
shell>?mysqladmin?-u?root?-p?shutdown
? ?-------
?
修改?anonymous?密碼
shell>?mysql?-u?root?-p
mysql>?SET?PASSWORD?FOR?''@'localhost'?=?PASSWORD('newpwd');
mysql>?SET?PASSWORD?FOR?''@'host_name'?=?PASSWORD('newpwd');shell>?mysql?-u?root?-p
mysql>?UPDATE?mysql.user?SET?password?=?PASSWORD('newpwd')->?WHERE?user?=?'';
mysql>?FLUSH?PRIVILEGES;
? ?-------??
刪除?anonymous?用戶
shell>?mysql?-u?root?-p
mysql>?DROP?USER?''@'localhost';
mysql>?DROP?USER?''@'host_name';
mysql>?select?host,user,password?from?mysql.user;
? ?-------
? ?拒絕任意用戶訪問測試數據庫
shell>?mysql?-u?root?-p
mysql>?DELETE?FROM?mysql.db?WHERE?db?LIKE?'test%';
mysql>?FLUSH?PRIVILEGES;mysql>?DROP?DATABASE?test;????(*?再進一步,連測試庫都干掉)
-----------------------------
使用 RPM 包安裝數據庫
? ?RPM 包可以是官方提供的,也可以是其他作者提供的;可能有所不同(文件結構)。
? ?標準安裝,需要 MySQL-server & MySQL-client 。(其他的包在標準安裝中不需要)
? ?4109 行有關于各種包(名稱)代表含義的詳細說明。(包對 CPU 是有選擇的 4208 )
? ?查看 RPM 包里的文件:
shell>?rpm?-qpl?MySQL-server-VERSION.glibc23.i386.rpm
? ?-------
? ?* Red Hat Linux, Fedora, CentOS
root-shell>?yum?install?mysql?mysql-server?mysql-libs
root-shell>?service?mysqld?start
root-shell>?chkconfig?--levels?235?mysqld?on
?
? ?-------
? ?Debian,Ubuntu,Kubuntu
root-shell>?apt-get?install?mysql-client-5.1?mysql-server-5.1
root-shell>?service?mysql?start?|?stop
-----------------------------
優化從編譯個出色的mysqld開始
???使用最好的編譯器、和最佳的編譯選項;使用靜態模板編譯。這個很重要,性能能提升10-30%。直接在官網下載的二進制包,包含所有的字符集;自己編譯可以選擇需要的字符集。Here?is?a?list?of?some?measurements?that?we?have?made:*?If?you?link?dynamically?(without?-static),?the?result?is?13%slower?on?Linux.?Note?that?you?still?can?use?a?dynamicallylinked?MySQL?library?for?your?client?applications.?It?is?theserver?that?is?most?critical?for?performance.*?For?a?connection?from?a?client?to?a?server?running?on?the?samehost,?if?you?connect?using?TCP/IP?rather?than?a?Unix?socketfile,?performance?is?7.5%?slower.?(On?Unix,?if?you?connect?tothe?host?name?localhost,?MySQL?uses?a?socket?file?by?default.)*?For?TCP/IP?connections?from?a?client?to?a?server,?connectingto?a?remote?server?on?another?host?is?8%?to?11%?slower?thanconnecting?to?a?server?on?the?same?host,?even?for?connectionsfaster?than?100Mb/s?Ethernet.*?When?running?our?benchmark?tests?using?secure?connections?(alldata?encrypted?with?internal?SSL?support)?performance?was?55%?slower?than?with?unencrypted?connections.*?On?a?Sun?UltraSPARC-IIe,?a?server?compiled?with?Forte?5.0?is4%?faster?than?one?compiled?with?gcc?3.2.*?On?a?Sun?UltraSPARC-IIe,?a?server?compiled?with?Forte?5.0?is4%?faster?in?32-bit?mode?than?in?64-bit?mode.*?Compiling?on?Linux-x86?using?gcc?without?frame?pointers(-fomit-frame-pointer?or?-fomit-frame-pointer?-ffixed-ebp)makes?mysqld?1%?to?4%?faster.
這段保留一點原汁原味
轉載于:https://blog.51cto.com/sunnybay/1375274
總結
以上是生活随笔為你收集整理的MySQL安装、基本账户安全(5.0以后版本)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。