運維開發技術交流羣歡迎你們加入一塊兒學習(QQ:722381733)mysql
前言:這裏我使用的安裝方式是(cmake編譯),我選擇的版本是:cmake-2.8.8.tar.gz、mysql-5.5.32.tar.gzsql
[root@mysql package]# ll total 29580 -rw-r--r-- 1 root root 5691656 May 29 11:52 cmake-2.8.8.tar.gz -rw-r--r-- 1 root root 24596474 May 29 11:53 mysql-5.5.32.tar.gz [root@mysql package]#
1、安裝cmake數據庫
一、解壓cmake壓縮包centos
[root@mysql package]# tar xf cmake-2.8.8.tar.gz [root@mysql package]# ls cmake-2.8.8 cmake-2.8.8.tar.gz mysql-5.5.32.tar.gz [root@mysql package]#
二、解析app
[root@mysql package]# cd cmake-2.8.8 [root@mysql cmake-2.8.8]# ./configure --------------------------------------------- CMake 2.8.8, Copyright 2000-2011 Kitware, Inc. Found GNU toolchain C compiler on this system is: gcc C++ compiler on this system is: g++ Makefile processor on this system is: gmake g++ is GNU compiler g++ has STL in std:: namespace g++ has ANSI streams g++ has streams in std:: namespace
三、安裝運維
[root@mysql cmake-2.8.8]# echo $? 0 [root@mysql cmake-2.8.8]# gmake && gmake install Scanning dependencies of target cmIML_test [ 1%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test.c.o [ 1%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_ABI_C.c.o [ 1%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_INT_C.c.o [ 1%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_include_C.c.o [ 2%] Building CXX object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_ABI_CXX.cxx.o [ 2%] Building CXX object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_INT_CXX.cxx.o [ 2%] Building CXX object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_include_CXX.cxx.o
注:安裝完成後,記得使用「echo $?」,檢查下!輸出0表示成功,輸出1表示失敗。socket
2、開始安裝mysql tcp
一、首先須要安裝(ncurses-devel)依賴包ide
[root@mysql cmake-2.8.8]# cd .. [root@mysql package]# yum install ncurses-devel -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * extras: centos.ustc.edu.cn * updates: mirrors.zju.edu.cn Resolving Dependencies --> Running transaction check ---> Package ncurses-devel.x86_64 0:5.9-14.20130511.el7_4 will be installed
#############安裝完成後檢查###########
[root@mysql package]# rpm -aq|grep ncurses-devel
ncurses-devel-5.9-14.20130511.el7_4.x86_64
[root@mysql package]#
二、解壓mysql壓縮包學習
[root@mysql package]# tar xf mysql-5.5.32.tar.gz [root@mysql package]# ls cmake-2.8.8 cmake-2.8.8.tar.gz mysql-5.5.32 mysql-5.5.32.tar.gz [root@mysql package]#
三、建立虛擬用戶
[root@mysql package]# useradd mysql -s /sbin/nologin -M [root@mysql package]# id mysql uid=1000(mysql) gid=1000(mysql) groups=1000(mysql) [root@mysql package]#
四、配置解析
[root@mysql package]# cd mysql-5.5.32 [root@mysql mysql-5.5.32]# [root@mysql mysql-5.5.32]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.32 -DMYSQL_DATADIR=/usr/local/mysql-5.5.32/data -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
五、安裝
[root@mysql mysql-5.5.32]# make && make install Scanning dependencies of target INFO_BIN [ 0%] Built target INFO_BIN Scanning dependencies of target INFO_SRC [ 0%] Built target INFO_SRC Scanning dependencies of target abi_check [ 0%] Built target abi_check Scanning dependencies of target zlib
六、建立軟鏈接
[root@mysql mysql-5.5.32]# ln -s /usr/local/mysql-5.5.32/ /usr/local/mysql [root@mysql mysql-5.5.32]# readlink /usr/local/mysql /usr/local/mysql-5.5.32/ [root@mysql mysql-5.5.32]#
七、配置環境
[root@mysql mysql-5.5.32]# cd .. [root@mysql package]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile [root@mysql package]# tail -1 /etc/profile export PATH=/usr/local/mysql/bin:$PATH [root@mysql package]# source /etc/profile [root@mysql package]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@mysql package]#
八、拷貝、查看、設置屬主、及添加tmp權限
[root@mysql package]# \cp mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf [root@mysql package]# ll /usr/local/mysql/data/ total 0 drwxr-xr-x 2 root root 20 May 31 11:51 test [root@mysql package]# chown -R mysql.mysql /usr/local/mysql/data/ [root@mysql package]# chmod -R 1777 /tmp/ [root@mysql package]#
九、初始化數據庫
[root@mysql package]# cd /usr/local/mysql/scripts/ [root@mysql scripts]# ./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql Installing MySQL system tables... OK Filling help tables... OK
注:看到兩個ok表示成功
十、設置開機啓動
[root@mysql scripts]# cd /package/mysql-5.5.32 [root@mysql mysql-5.5.32]# /bin/cp support-files/mysql.server /etc/init.d/mysqld [root@mysql mysql-5.5.32]# chmod +x /etc/init.d/mysqld [root@mysql mysql-5.5.32]# chkconfig --add mysqld [root@mysql mysql-5.5.32]# chkconfig mysqld on [root@mysql mysql-5.5.32]# chkconfig --list mysqld Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@mysql mysql-5.5.32]#
十一、啓動mysql數據庫
[root@mysql mysql-5.5.32]# /etc/init.d/mysqld start Starting MySQL.. SUCCESS! [root@mysql mysql-5.5.32]#
十二、查看端口進程
[root@mysql mysql-5.5.32]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 51146 mysql 10u IPv4 82600 0t0 TCP *:mysql (LISTEN) [root@mysql mysql-5.5.32]# netstat -lnutp|grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 51146/mysqld [root@mysql mysql-5.5.32]# ps -ef|grep 3306 mysql 51146 50900 0 14:13 pts/1 00:00:00 /usr/local/mysql-5.5.32/bin/mysqld --basedir=/usr/local/mysql-5.5.32 --datadir=/usr/local/mysql-5.5.32/data --plugin-dir=/usr/local/mysql-5.5.32/lib/plugin --user=mysql --log-error=/usr/local/mysql-5.5.32/data/mysql.err --pid-file=/usr/local/mysql-5.5.32/data/mysql.pid --socket=/usr/local/mysql-5.5.32/tmp/mysql.sock --port=3306 root 51170 16240 0 14:14 pts/1 00:00:00 grep --color=auto 3306 [root@mysql mysql-5.5.32]#
注:若是要從新初始化只要刪除data目錄庫文件存儲地或者新建一個庫文件存儲地,從新初始化,提示兩個ok就是成功
##這裏就基本上安裝好了,有沒有以爲比make&&make install高大上一點哈,下面是一些mysql的優化。
3、mysql數據的一些小優化
這裏就不一一說明了,主要是本身懶並且菜,但願能知足大夥的工做要求
進入數據庫
mysql 查看全部用戶 select user,host from mysql.user; (方式一)刪除系統默認的 delete from mysql.user where user=''; delete from mysql.user where host='主機名'; delete from mysql.user where host='::1'; select user,host from mysql.user; ##### 只保留這兩個 ####### mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | localhost | +------+-----------+ 2 rows in set (0.00 sec) mysql> ######################### 刪除test庫 drop database test; show databases; (方式二)乾脆把所有刪除了,添加額外的管理員 刪除所有用戶 delete from mysql.user; 添加額外的受權管理員用戶 grant all privileges on *.* to system@'localhost' identified by '123456' with grant option; 字符集路徑 vi /etc/locale.conf #centos7 vi /etc/sysconfig/il8n #centos6 mysql建立密碼 /application/mysql//bin/mysqladmin -u root password '123456' mysql修改密碼 /application/mysql//bin/mysqladmin -u root -poldboy123 password '112233'