1. 程式人生 > >MySQL 5.5單實例 編譯安裝

MySQL 5.5單實例 編譯安裝

數據庫基礎學習

1、建立MySQL賬號

首先以root登錄到Linux,然後執行如下命令創建MySQL組及用戶

  [[email protected] home]# groupadd mysql
  [[email protected] home]# useradd -s /sbin/nologin -g mysql -M mysql
  [[email protected] home]# tail -1 /etc/passwd
  feitian:x:811:811::/home/mysql:/sbin/nologin(/sbin/nologin表示不能登錄)
  -s/sbin/nologin表示禁止登錄
  -gmysql指定屬於mysql組
  -M表示不創建家目錄。
  [[email protected]
/* */ tools]# cd /home/loveyu/tools/

2、編譯安裝MySQL

2.1獲得MySQL軟件

1》通過rz上傳

2》wgte 在搜狐的鏡像站點中下載 http://mirrors.sohu.com/mysql/MySQL-5.7/

2.2編譯[[email protected] tools]# tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

./configure \ 
--prefix=/usr/local/mysql \  #安裝路徑
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \  #指定socket文件存放
--localstatedir=/usr/local/mysql/data \  #MySQL數據文件存放位置
--enable-assembler \   #允許使用匯編模式
--enable-thread-safe-client --with-mysqld-user=mysql \    #指定MySQL運行的系統用戶
--with-big-tables--without-debug \       #使用非debug
--with-pthread \     #強制使用pthread線程序庫編譯
--enable-assembler --with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase,partition --enable-thread-safe-client \    #使用線程的方式編譯客戶端
--with-client-ldflags=-all-static  \    #服務端使用靜態庫
--with-mysqld-ldflags=-all-static        #客戶端使用靜態庫
#等待完成之後make && make install

3、獲取MySQL配置文件

[[email protected] mysql-5.1.72]#     ll  support-files/*.cnf
-rw-r--r-- 1 root root  4714 May 11 08:53 support-files/my-huge.cnf
-rw-r--r-- 1 root root 19763 May 11 08:53 support-files/my-innodb-heavy-4G.cnf
-rw-r--r-- 1 root root  4688 May 11 08:53 support-files/my-large.cnf
-rw-r--r-- 1 root root  4699 May 11 08:53 support-files/my-medium.cnf
-rw-r--r-- 1 root root  2467 May 11 08:53 support-files/my-small.cnf
#這裏有大中小和超大三個配置文件,這裏是試驗環境我們最好選最小的配置文件
[[email protected]
/* */ mysql-5.1.72]# /bin/cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf [[email protected] mysql-5.1.72]# ls -l /etc/my.cnf -rw-r--r-- 1 root root 19763 May 11 09:02 /etc/my.cnf

4、初始化數據庫,創建MySQL數據庫文件

[[email protected] data]# mkdir /usr/lacal/mysql/data -p
[[email protected] data]# chown -R mysql /usr/local/mysql
[[email protected] tools]# /application/mysql/scripts/mysql_install_db basedir=/application/mysql --datadir=/application/mysql/data --user=mysql

5、啟動數據庫

[[email protected] mysql-5.1.72]# cp support-files/mysql.server /usr/local/mysql/bin/
[[email protected] mysql-5.1.72]# chmod 700 /usr/local/mysql/bin/mysql.server 
[[email protected] tools]# /usr/local/mysql/bin/mysql.server start
Starting MySQL. SUCCESS! 
[[email protected] tools]# ps -ef|grep 3306
root     64252 63576  0 09:48 pts/0    00:00:00 grep 3306
[[email protected] mysql-test]#  /usr/local/mysql/bin/mysqld_safe &
[1] 64731
[[email protected] mysql]# 170511 11:50:09 mysqld_safe Logging to ‘/var/log/mysqld.log‘.
170511 11:50:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

6、配置MySQL命令全局使用路徑(/etc/profile)

PATH=$PATH:/usr/bin/mysql

7、配置/etc/init.d/mysqld start 的方式啟動數據庫

[[email protected] mysql-5.1.72]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql-5.1.72]# chmod 700 /etc/init.d/mysqld
[[email protected] mysql-5.1.72]# /etc/init.d/mysqld restart
Shutting down MySQL..... SUCCESS! 
Starting MySQL. SUCCESS!

8、設置開機自啟

[[email protected] mysql-5.1.72]# chkconfig --add mysqld
[[email protected] mysql-5.1.72]# chkconfig mysqld on
或者放入rc.local中

9、登陸MySQL數據庫 測試

9.1為root增加密碼

[[email protected] mysql-5.1.72]# mysqladmin -u root password ‘fenghui‘
[[email protected] mysql-5.1.72]# mysql
ERROR 1045 (28000): Access denied for user [email protected] (using password: NO)

9.2刪除多余用戶

mysql> select user,host from mysql.user;
+------+-----------+
|user | host   |
+------+-----------+
|root | 127.0.0.1|
|   | feitian |
|root | feitian |
|   | localhost|
|root | localhost|
+------+-----------+
5 rows in set (0.00 sec)
mysql> drop user ""@localhost;Query OK, 0 rows affected (0.00 sec)
mysql> drop user ""@feitian;Query OK, 0 rows affected (0.00 sec)
mysql> drop user [email protected];Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
|user  | host  |
+------+-----------+
|root |127.0.0.1 |
|root | localhost|
+------+-----------+
2 rows in set (0.00 sec)
如果用戶名中還有大寫字母,則用以下命令刪除
delete from mysql.user while user="" and host="大寫的用戶名"

錯誤總結:如果剛裝完數據庫啟動時出現如下出現錯誤,一般來說可以重新初始化數據文件即可,要將數據文件全部刪除。

ERROR 1045 (28000): Access denied for user [email protected] (using password: NO)


本文出自 “13122323” 博客,請務必保留此出處http://13132323.blog.51cto.com/13122323/1952012

MySQL 5.5單實例 編譯安裝