mysql 5.74安装教程_MySQL安装、基本账户安全(5.0以后版本)
-----------MySQL 5.0以后版本的安裝-----------
MySQL安裝
安裝包學(xué)習(xí)的必殺絕技——就是閱讀包的安裝說明(readme & install)文檔。
----------
# rm /etc/my.cnf ? ? ? ? ? ?(安裝前執(zhí)行一下)
----------
1.Mysql-5.0.40.tar.gz
1.1.Source Installation Overview(lines 74 of install-source)
系統(tǒng)默認(rèn)可能會安裝三個mysql的包:
mysql-libs
mysql
mysql-devel
從下往上依賴關(guān)系。
源碼包安裝mysql檢查環(huán)境
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
目錄權(quán)限
Shell>?cd?/usr/local/mysql
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
初始化數(shù)據(jù)庫
Shell>?bin/mysql_install_db?--user=mysql
開機(jī)啟動
Shell>?cp?/support-files/mysql.server?/etc/init.d/mysqld
Shell>?chmod?755?/etc/init.d/mysqld
安全啟動服務(wù)/把數(shù)據(jù)庫的數(shù)據(jù)文件定義到其他磁盤設(shè)備上
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
默認(rèn)安裝的目錄/usr/local(數(shù)據(jù)目錄/usr/local/var)。可以改寫為:
Shell>?./configure?--prefix=/usr/local/mysql
Shell>?./configure?--prefix=/usr/local/?--localstatedir=/usr/local/mysql/data
使用unix的套接字方式連接數(shù)據(jù)庫:
Shell>?./configure?--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
有g(shù)cc,沒有c++庫,可以使用gcc來作為c++的編譯器:
Shell>?CC=gcc?CXX=gcc?./configure
Shell>?./configure?--with-charset=gb2312
Shell>?./configure?--with-charset=utf8
Shell>?./configure?--with-charset=latin1(這個是默認(rèn)值)
Shell>?./configure?--with-collation=latin1_swedish_ci(這個是排序方法的默認(rèn)值)
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
系統(tǒng)默認(rèn)可能會安裝三個mysql的包:
mysql-libs
mysql
mysql-devel
從下往上依賴關(guān)系。
二進(jìn)制文件安裝mysql檢查環(huán)境
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?.
初始化數(shù)據(jù)庫
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
啟動服務(wù)
Shell>?bin/mysqld_safe?--user=mysql?--datadir=/dell/mysql_data
2.2.Installing MySQL from Source
源碼包安裝mysql檢查環(huán)境
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?.(先進(jìn)行交互式配置)
Shell>?cmake?.
Shell>?make
Shell>?make?install
Shell>?cd?/usr/local/mysql
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
初始化數(shù)據(jù)庫
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
啟動服務(wù)
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.rpmTo?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.rpm
Start?from?a?source?RPM,run:
Shell>?rpmbuild?--rebuild?--clean?MySQL-VERSION.src.rpm
2.5.安裝Cmake-2.8.12.tar.gzShell>?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
二進(jìn)制包安裝mysql檢查當(dāng)前環(huán)境配置
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
設(shè)定目錄權(quán)限
Shell>?chown?-R?mysql?.
Shell>?chgrp?-R?mysql?.
初始化數(shù)據(jù)庫
Shell>?scripts/mysql_install_db?--user=mysql
設(shè)定庫文件目錄權(quán)限
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
啟動服務(wù)
Shell>?bin/mysqld_safe?--user=mysql?--datadir=/dell/mysql_data
3.2.Installing MySQL Using a Standard Source Distribution
源碼包安裝mysqlShell>?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?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
二進(jìn)制包安裝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/
標(biāo)準(zhǔn)啟動
[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
添加啟動時打開服務(wù)
[root@tri?mysql]#?cp?support-files/mysql.server?/etc/init.d/mysql
打開上述文件(提示配置文件、主目錄、數(shù)據(jù)目錄)
[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=
#?-?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 安裝完成后的帳號安全問題-----------
問題描述
剛安裝好的系統(tǒng), root 默認(rèn)密碼為空;默認(rèn)空用戶(空密碼)也可以在本地登錄;
查看系統(tǒng)中有那些賬戶:無用戶名、密碼本地登錄
[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)
顯示結(jié)果,表示有多個 root 用戶;有兩個 空用戶。沒有一個有密碼。
這就需要為每一個用戶設(shè)定密碼;同樣需要為空用戶設(shè)定密碼,或者刪除。
mysql.db 中的某些行,允許所有用戶(包括沒有密碼的空賬戶;anonymous)訪問測試數(shù)據(jù)庫或者其
他以 “test_” 開頭的數(shù)據(jù)庫。(這個默認(rèn)設(shè)置是為了測試的)
-------
修改 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;
-------
拒絕任意用戶訪問測試數(shù)據(jù)庫shell>?mysql?-u?root?-p
mysql>?DELETE?FROM?mysql.db?WHERE?db?LIKE?'test%';
mysql>?FLUSH?PRIVILEGES;
mysql>?DROP?DATABASE?test;????(*?再進(jìn)一步,連測試庫都干掉)
-----------------------------
使用 RPM 包安裝數(shù)據(jù)庫
RPM 包可以是官方提供的,也可以是其他作者提供的;可能有所不同(文件結(jié)構(gòu))。
標(biāo)準(zhǔn)安裝,需要 MySQL-server & MySQL-client 。(其他的包在標(biāo)準(zhǔn)安裝中不需要)
4109 行有關(guān)于各種包(名稱)代表含義的詳細(xì)說明。(包對 CPU 是有選擇的 4208 )
查看 RPM 包里的文件:shell>?rpm?-qpl?MySQL-server-VERSION.glibc23.i386.rpm
-------
* Red Hat Linux, Fedora, CentOSroot-shell>?yum?install?mysql?mysql-server?mysql-libs
root-shell>?service?mysqld?start
root-shell>?chkconfig?--levels?235?mysqld?on
-------
Debian,Ubuntu,Kubunturoot-shell>?apt-get?install?mysql-client-5.1?mysql-server-5.1
root-shell>?service?mysql?start?|?stop
-----------------------------
優(yōu)化從編譯個出色的mysqld開始使用最好的編譯器、和最佳的編譯選項;使用靜態(tài)模板編譯。這個很重要,性能能提升10-30%。
直接在官網(wǎng)下載的二進(jìn)制包,包含所有的字符集;自己編譯可以選擇需要的字符集。
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?dynamically
linked?MySQL?library?for?your?client?applications.?It?is?the
server?that?is?most?critical?for?performance.
*?For?a?connection?from?a?client?to?a?server?running?on?the?same
host,?if?you?connect?using?TCP/IP?rather?than?a?Unix?socket
file,?performance?is?7.5%?slower.?(On?Unix,?if?you?connect?to
the?host?name?localhost,?MySQL?uses?a?socket?file?by?default.)
*?For?TCP/IP?connections?from?a?client?to?a?server,?connecting
to?a?remote?server?on?another?host?is?8%?to?11%?slower?than
connecting?to?a?server?on?the?same?host,?even?for?connections
faster?than?100Mb/s?Ethernet.
*?When?running?our?benchmark?tests?using?secure?connections?(all
data?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?is
4%?faster?than?one?compiled?with?gcc?3.2.
*?On?a?Sun?UltraSPARC-IIe,?a?server?compiled?with?Forte?5.0?is
4%?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.
這段保留一點原汁原味
總結(jié)
以上是生活随笔為你收集整理的mysql 5.74安装教程_MySQL安装、基本账户安全(5.0以后版本)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 海星泡酒的功效与作用、禁忌和食用方法
- 下一篇: php mysql 子查询_php –