源碼安裝mysql

來源:互聯網
上載者:User

標籤:源碼安裝mysql

建立mysql組:
groupadd mysql

建立mysql使用者並賦予這個mysq組中,不建立家目錄,不允許使用者登入。(因為剛剛建立的mysql是虛擬使用者,所以不允許登入)
useradd mysql -g mysql -M -s /bin/nologin

源碼安裝mysql
解壓後進行編譯安裝:
./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

make && make make install


安裝好後 建立mysql的軟連結:
ln -s /application/mysql5.1.72/ /application/apache

在該目錄下查看/usr/local/tools/mysql-5.1.72/support-files/下面cnf的設定檔    這些檔案都是預設的設定檔的模版,適合與不同的情境
[[email protected] support-files]# ll  my*.cnf
-rw-r--r-- 1 root root  4746 05-04 02:49 my-huge.cnf         第四小            這些是根據伺服器的硬體設定來衡量,伺服器硬體過低,用最小的,配置高,用最大
-rw-r--r-- 1 root root 19779 05-04 02:49 my-innodb-heavy-4G.cnf     最大的
-rw-r--r-- 1 root root  4720 05-04 02:49 my-large.cnf        第三小
-rw-r--r-- 1 root root  4731 05-04 02:49 my-medium.cnf       最小的
-rw-r--r-- 1 root root  2499 05-04 02:49 my-small.cnf        第二小
然後將其中選擇適合你的伺服器的設定檔拷貝到/etc下
[[email protected] support-files]# cp my-small.cnf /etc/my.cnf

建立mysql資料庫存放資料的目錄:
[[email protected] ~]# mkdir  /application/mysql/data -p

給/application/mysql/目錄授予mysql使用者和mysql組的許可權
[[email protected] ~]# chown -R mysql.mysql  /application/mysql/

初始化資料檔案
[[email protected] ~]#/application/mysql/bin/mysql_install_db  --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

plication/mysql/data/ --user=mysql
Installing MySQL system tables...
170504  4:34:50 [Warning] ‘--skip-locking‘ is deprecated and will be removed in a future release. Please use ‘--skip-external-locking‘ instead.
OK
Filling help tables...
170504  4:34:50 [Warning] ‘--skip-locking‘ is deprecated and will be removed in a future release. Please use ‘--skip-external-locking‘ instead.
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/application/mysql//bin/mysqladmin -u root password ‘new-password‘
/application/mysql//bin/mysqladmin -u root -h node1.com password ‘new-password‘

Alternatively you can run:
/application/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql//scripts/mysqlbug script!


現在mysql就已經安裝完成,到data目錄下查看會產生兩個庫:
[[email protected] ~]# ll /application/mysql/data/
總計 8
drwx------ 2 mysql root 4096 05-04 04:34 mysql     系統的庫,
drwx------ 2 mysql root 4096 05-04 04:34 test      測試的庫,建議刪除,不安全。

[[email protected] init.d]# /application/mysql//bin/mysqld_safe &
[1] 17071
[[email protected] init.d]# 170504 04:48:46 mysqld_safe Logging to ‘/application/mysql5.1.72/data/node1.com.err‘.
170504 04:48:47 mysqld_safe Starting mysqld daemon with databases from /application/mysql5.1.72/data

[[email protected] init.d]#
[[email protected] init.d]#
[[email protected] init.d]#
[[email protected] init.d]#
[[email protected] init.d]#
[[email protected] init.d]# netstat -tulnp | grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17179/mysqld        




啟動mysql 以start方式啟動
[[email protected] init.d]# cp /usr/local/tools/mysql-5.1.72/support-files/mysql.server /etc/init.d/mysqld
[[email protected] init.d]# chmod +x /etc/init.d/mysqld

儲存之後就可以啟動了。



mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;    
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
|      | localhost |
| root | localhost |
|      | node1.com |
| root | node1.com |
+------+-----------+
5 rows in set (0.00 sec)

mysql> drop user ""@localhost
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> drop user ""@node1.com
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
| root | node1.com |
+------+-----------+
3 rows in set (0.00 sec)

源碼安裝mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.