1. 程式人生 > 實用技巧 >1,mysql的安裝

1,mysql的安裝

Mysql 不同版本市場佔有比例  
mysql 5.1 20%  
mysql 5.5 60% 
mysql5.6  20%

一般公司用的是社群版:
MySQL Community Edition(GPL)
Community (GPL) Downloads »

下載連結:https://dev.mysql.com/downloads/mysql/

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd mysql -g mysql -M -s /sbin/nologin
[root@localhost ~]# cd /home/oldboy/tools/
[root@localhost tools]# tar xf mysql-5.1.72.tar.gz
[root@localhost tools]# cd mysql-5.1.72
[root@localhost mysql-5.1.72]# yum install ncurses-devel   gcc
[root@localhost mysql-5.1.72]# pwd
/home/oldboy/tools/mysql-5.1.72
[root@localhost mysql-5.1.72]# cat log.sh
./configure \
--prefix=/application/mysql5.1.72 \
--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock \
--localstatedir=/application/mysql5.1.72/data \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=complex \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static
[root@localhost mysql-5.1.72]# cat log.sh |bash

 

config.status: creating include/config.h
config.status: executing depfiles commands
config.status: executing libtool commands
/usr/bin/rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands
Thank you for choosing MySQL!

 

Remember to check the platform specific part of the reference manual
for hints about installing MySQL on your platform.
Also have a look at the files in the Docs directory.
[root@localhost mysql-5.1.72]# echo $?
0
[root@localhost mysql-5.1.72]# make && make install
[root@localhost mysql-5.1.72]# ln -s /application/ mysql-5.1.72 / /application/mysql

如果mysql和web伺服器不在同一臺機器,到上面步驟,安裝完畢資料庫!!
如果在同一臺機器上,就接著執行如下步驟。

 

[root@localhost support-files]# pwd
/home/oldboy/tools/mysql-5.1.72/support-files
[root@localhost support-files]#
[root@moban support-files]#  ll my-*.cnf
-rw-r--r--. 1 root root  4746 May 25 22:59 my-huge.cnf
-rw-r--r--. 1 root root 19779 May 25 22:59 my-innodb-heavy-4G.cnf
-rw-r--r--. 1 root root  4720 May 25 22:59 my-large.cnf
-rw-r--r--. 1 root root  4731 May 25 22:59 my-medium.cnf
-rw-r--r--. 1 root root  2499 May 25 22:59 my-small.cnf

[root@localhost support-files]# cp my-small.cnf  /etc/my.cnf  (初始化資料庫配置檔案)
建立mysql資料檔案目錄

[root@localhost support-files]# mkdir /application/mysql/data -p
[root@localhost support-files]# chown -R mysql.mysql /application/mysql/
資料庫初始化 [root@localhost support-files]# /application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql [root@localhost support-files]# cp mysql.server /etc/init.d/mysqld [root@localhost support-files]# chkconfig --add mysqld [root@localhost support-files]# chkconfig mysqld on [root@localhost support-files]# chmod +x /etc/init.d/mysqld [root@localhost support-files]# /etc/init.d/mysqld start [root@localhost support-files]# 到此就安裝完成了。 接下來就是登陸mysql了。一開始是沒有密碼的,直接就可以登陸。 [root@httpd support-files]# mysql //直接登入(可能出現問題) 必須將mysql 加到系統環境變數才能知道MySQL是哪個。 [root@localhost support-files]# vim /etc/profile [root@localhost support-files]# grep mysql /etc/profile PATH="/application/mysql/bin/:$PATH" [root@localhost support-files]# ./etc/profile //讓它生效 [root@localhost support-files]#mysql -uroot -p //就可以登入了 [root@localhost support-files]# 剛剛建立root還沒有密碼,可以為他建立個密碼: /application/mysql/bin/mysqladmin -u root -h moban password 'new-password' 第一種方法:(是哪種啟動就用哪種關閉) 啟動: /application/mysql/bin/mysqld_safe & 關閉: mysqladmin shutdown 第二種方法:(混合用有問題) /etc/init.d/mysqld start /etc/init.d/mysqld stop 注意:安裝過程出現這個報錯: [root@moban support-files]# /etc/init.d/mysqld start Starting MySQL. ERROR! Manager of pid-file quit without updating file. [root@moban support-files]# /application/mysql/bin/mysqld_safe & [1] 46355 [root@moban support-files]# 180526 00:19:21 mysqld_safe Logging to '/var/log/mysqld.log'. 180526 00:19:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 180526 00:19:21 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 解決方法:再次執行 [root@localhost support-files]# /application/mysql/bin/mysql_install_db [root@moban bin]# ps -ef|grep mysql root 75378 1 0 10:47 pts/0 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/moban.pid mysql 75467 75378 0 10:47 pts/0 00:00:00 /application/mysql/libexec/mysqld --basedir=/application/mysql --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/moban.pid --socket=/var/lib/mysql/mysql.sock root 101511 1926 0 11:27 pts/0 00:00:00 grep mysql [root@moban bin]# [root@moban bin]# find / -name "mysql.sock" /var/lib/mysql/mysql.sock [root@moban bin]# /application/mysql/bin/mysql -u root -p -S /var/lib/mysql/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.72 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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>