linux下的mysql源码安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/silenceray/article/details/72473175
第一次接触mysql,linux下的。以前都是Windows上的,今天有兴趣安装试试
环境red hat 6.5 x64
mysql5.6.12
1.下载mysql的源码包
http://www.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.12.tar.gz/from/http://cdn.mysql.com/
建立mysql用户、安装目录、数据目录
[root@pg ~]#  /usr/sbin/groupadd mysql
[root@pg ~]#  /usr/sbin/useradd -g mysql mysql
[root@pg ~]# mkdir /opt/mysql
[root@pg ~]# mkdir -p /opt/mysqldata/data
[root@pg ~]# chown -R mysql:mysql /opt/mysql
[root@pg ~]# chown -R mysql:mysql /opt/mysqldata/data/
[root@pg ~]# su - mysql
[mysql@pg ~]$ cd /tmp
[mysql@pg tmp]$ tar -xvf mysql-5.6.12.tar.gz 
[mysql@pg tmp]$cd mysql-5.6.12
在进行编译的时候需要用到cmake ,可以有yum直接安装一下,也可以去下载一个cmake安装一下
[mysql@pg mysql-5.6.12]$ cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/opt/mysqldata/data/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
关于cmake的一些参数介绍	
# -DCMAKE_INSTALL_PREFIX=/opt/mysql         \    #安装路径
# -DMYSQL_DATADIR=/opt/mysqldata/data/          \    #数据文件存放位置
# -DSYSCONFDIR=/etc                                \    #my.cnf路径
# -DWITH_MYISAM_STORAGE_ENGINE=1                   \    #支持MyIASM引擎
# -DWITH_INNOBASE_STORAGE_ENGINE=1                 \    #支持InnoDB引擎
# -DWITH_MEMORY_STORAGE_ENGINE=1                   \    #支持Memory引擎
# -DWITH_READLINE=1                                \    #快捷键功能(我没用过)
# -DMYSQL_UNIX_ADDR=/tmp/mysql.sock               \    #连接数据库socket路径
# -DMYSQL_TCP_PORT=3306                            \    #端口
# -DENABLED_LOCAL_INFILE=1                         \    #允许从本地导入数据
# -DWITH_PARTITION_STORAGE_ENGINE=1                \    #安装支持数据库分区
# -DEXTRA_CHARSETS=all                             \    #安装所有的字符集
# -DDEFAULT_CHARSET=utf8                           \    #默认字符
# -DDEFAULT_COLLATION=utf8_general_ci
[mysql@pg mysql-5.6.12]$ make 
[mysql@pg mysql-5.6.12]$ make insatll
注意:

重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
[mysql@pg mysql-5.6.12]$ make
[mysql@pg mysql-5.6.12]$ make install
修改my.cnf文件
[mysql@pg mysql]$ cp support-files/my-medium.cnf /etc/my.cnf  
注意etc的权限
[root@pg mysql]$chown -R mysql:mysql /etc/
在[mysqld]添加一下内容
datadir = /opt/mysqldata/data
port = 3306
socket = /tmp/mysql.sock
user=mysql

初始化数据库
[mysql@pg mysql]$ scripts/mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysqldata/data --user=mysql 
启动数据库
[mysql@pg mysql]$ ./bin/mysqld_safe --user=mysql &
[1] 39498
[mysql@pg mysql]$ 170518 15:10:40 mysqld_safe Logging to '/opt/mysqldata/data/pg.err'.
170518 15:10:41 mysqld_safe Starting mysqld daemon with databases from /opt/mysqldata/data
[mysql@pg bin]$ ./mysql -u mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.12 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> use test;
Database changed
mysql> create table a (a int);
Query OK, 0 rows affected (0.10 sec)

mysql> insert into a value (1);
Query OK, 1 row affected (0.03 sec)

mysql> insert into a value (2);
Query OK, 1 row affected (0.00 sec)

mysql> insert into a value (3);
Query OK, 1 row affected (0.05 sec)

mysql> select * from a;
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql> exit
Bye
如果想使用mysql数据库的话 就得用root用户了
mysql@pg bin]$ ./mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.12 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> exit
Bye
另一种启动数据库的方式
[root@pg mysql]$ cp support-files/mysql.server  /etc/init.d/mysql 
[root@pg data]# service mysql start
[root@pg data]# service mysql stop
[root@pg data]#service mysql restart
[root@pg data]# service mysql status
MySQL running (39652)                                      [  OK  ]
[root@pg data]# ps -ef | grep mysql
root      22609   2260  0 13:40 pts/0    00:00:00 su - mysql
mysql     22610  22609  0 13:40 pts/0    00:00:00 -bash
mysql     39498  22610  0 15:10 pts/0    00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql
mysql     39652  39498  0 15:10 pts/0    00:00:04 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysqldata/data --plugin-dir=/opt/mysql/lib/plugin --log-error=/opt/mysqldata/data/pg.err --pid-file=/opt/mysqldata/data/pg.pid --socket=/tmp/mysql.sock --port=3306
root      40324   6837  0 16:14 pts/1    00:00:00 grep mysql
将mysql的启动服务添加到系统服务中  
[root@pg data]chkconfig --add mysql                              #添加系统服务 
[root@pg data]chkconfig mysql on                                 #添加开机启动

猜你喜欢

转载自blog.csdn.net/silenceray/article/details/72473175