linux編譯安裝mysql


本教程的系統平台:CentOS release 6.8 (Final) 64位。mysql5.6.15,cmake-3.1.1

一、安裝編譯工具及庫文件

yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel

二、 安裝cmake 編譯器

1、下載地址:http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz

$ wget http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz

2、解壓安裝包

$ tar zxvf cmake-3.1.1.tar.gz

3.進入安裝包目錄

$ cd cmake-3.1.1

4、編譯安裝 

$ ./bootstrap
$ make && make install

三、安裝 MySQL

1、下載地址: http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz

2、解壓安裝包

$ tar zxvf mysql-5.6.15.tar.gz

3、進入安裝包目錄

$ cd mysql-5.6.15

4、編譯安裝 

$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_INNODB_MEMCACHED=1 -DWITH_DEBUG=OFF -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306
$ make && make install

MySQL 配置

1、創建mysql運行使用的用戶mysql:

$ /usr/sbin/groupadd mysql
$ /usr/sbin/useradd -g mysql mysql

2、創建binlog存儲路徑並賦予mysql用戶權限

$ mkdir -p /usr/local/mysql/binlog 
$ chown mysql.mysql /usr/local/mysql/binlog/ 



3、授權用戶
$chown -R mysql:mysql /usr/local/mysql/
$chown -R mysql:mysql /data $chmod 1777 /tmp

4創建my.cnf配置文件

[root@bogon mysql]# cp support-files/my-default.cnf  /etc/my.cnf

5.設置環境變量

[root@bogon mysql]# cp support-files/my-default.cnf  /etc/my.cnf
cp:是否覆蓋"/etc/my.cnf"? y
[root@bogon mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@bogon mysql]# source !$
source /etc/profile

6.創建服務腳本添加開機啟動

[root@bogon mysql]# cp support-files/mysql.server  /etc/init.d/mysqld
[root@bogon mysql]# chmod +x /etc/init.d/mysqld [root@bogon mysql]# vim /etc/init.d/mysqld
//服務啟動腳本要修改以下兩個參數 
basedir=/usr/local/mysql //MySQL安裝目錄 
datadir= /data //數據存放目錄 

    添加開機啟動

[root@bogon mysql]# chkconfig mysqld on

7.初始化數據庫 

  注:到這一步很容易出問題,在初始化的時候一定要加上面的參數,而且在執行這一步操作前/data/mysql/data 這個目錄必須是空的;在這里指定的basedir 和 datadir 目錄必須要和/etc/my.cnf 配置的目錄一直才行。

[root@bogon mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql --datadir=/data

 

8.啟動

[root@bogon mysql]# service mysqld start
Starting MySQL. SUCCESS! 
[root@bogon mysql]# service mysqld  status
 SUCCESS! MySQL running (29614)

9.登陸和創建用戶

[root@bogon mysql]# mysql -u root -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.15 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> show database
-> G
->
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database
G' at line 1
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)

  (1)你想root使用mypassword從任何主機連接到mysql服務器的話。 

     GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 

 

     如果你想允許用戶myuser從ip為192.168.1.3的主機連接到mysql服務器,並使用mypassword作為密碼 
 

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 

    輸入命令

    FLUSH PRIVILEGES; 

 

新增用戶並授權

mysql> grant all privileges on *.* to xueqing @'%' identified by '123456mysql>grant all privileges on *.* to xueqing @'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)

 語法:grant all privileges on *.* to 用戶名@'%' identified by '密碼' with grant option;

mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table xueqing(id int auto_increment,name char(20),primary key(id))engine=myisam default charset=utf8;
Query OK, 0 rows affected (0.01 sec)

10,用mysql圖像管理器登陸

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM