标签:mysql linux
经过看了几篇文档,都没有写完全。稍微整理了一下,重新一步一步进行编译安装mysql在centos7上。
安装步骤如下:
1、安装编译环境
# yum -y install gcc- gcc-c++ ncurses-devel per |
2、建立mysql目录和帐号,及目录属性
# mkdir -p /data/mydata # mkdir -p /usr/local/mysql # useradd -d /data/mydata -s /sbin/nologin -g mysql mysql # cd data/mydata/ # chown -R mysql:mysql . # cd /usr/local/mysql/ # chown -R mysql:mysql . |
3、下载copy到系统里
# cd # ls anaconda-ks.cfg mysql-5.6.22.tar.gz |
4、解压mysql源码包
# tar -zxvf mysql-5.6.22.tar.g |
5、编译mysql源码包
说明:从mysql5.5起,mysql源码安装开始使用cmake了,设置源码编译配置脚本。
-DCMAKE_INSTALL_PREFIX=dir_name | 设置mysql安装目录 |
-DMYSQL_UNIX_ADDR=file_name | 设置监听套接字路径,这必须是一个绝对路径名。默认为/tmp/mysql.sock |
-DDEFAULT_CHARSET=charset_name | 设置服务器的字符集。 |
-DDEFAULT_COLLATION=collation_name | 设置服务器的排序规则。 |
-DWITH_INNOBASE_STORAGE_ENGINE=1 | 存储引擎选项: |
-DMYSQL_DATADIR=dir_name | 设置mysql数据库文件目录 |
-DMYSQL_TCP_PORT=port_num | 设置mysql服务器监听端口,默认为3306 |
-DENABLE_DOWNLOADS=bool | 是否要下载可选的文件。例如,启用此选项(设置为1),cmake将下载谷歌所使用的测试套件运行单元测试。 |
# cd mysql-5.6.22 # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=mysql.mysql -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWIT H_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mydata -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 [root@localhost mysql-5.6.22]# make [root@localhost mysql-5.6.22]# make install |
6、初始化mysql数据库
# cd scripts/ # ls mysql_install_db # ./mysql_install_db --user=mysql --datadir=/data/mydata FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db: Data::Dumper 初始化过程中会报错,需要安装perl-Module-Install.noarch # yum install -y perl-Module-Install.noarch # scripts/mysql_install_db --user=mysql --datadir=/data/mydata 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:
./bin/mysqladmin -u root password ‘new-password‘ ./bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘
Alternatively you can run:
./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings |
7、复制mysql服务和启动文件
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
|
8、开启mysqld服务
[root@localhost ~]# service mysqld start Starting MySQL. SUCCESS! |
9、添加到chkconfig里
[root@localhost ~]# chkconfig [root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# chkconfig --list iprdump 0:off 1:off 2:on 3:on 4:on 5:on 6:off iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off 检查端口 [root@localhost ~]# netstat -tulnp | grep 3306 tcp6 0 0 :::3306 :::* LISTEN 21466/mysqld |
10、设置环境变量PATH路径
[root@localhost /]# vi /etc/profile -- INSERT --
PATH=/usr/local/mysql/bin:$PATH export PATH :wq "/etc/profile" # source /etc/profile |
11、进入数据库报错
[root@localhost /]# mysql -uroot ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘mysql.mysql‘ (2) |
12、编辑my.cnf
[root@localhost ~]# vi /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/data/mydata port=3306 socket=/data/mydata/mysql.sock server_id=1 [mysqld_safe] log-error=/data/log/mysqld.log [mysql] socket=/data/mydata/mysql.sock [mysqldump] socket=/data/mydata/mysql.sock [mysqladmin] socket=/data/mydata/mysql.sock |
13、重启mysqld服务
# etc/init.d/mysqld restart |
14、进入数据库并设置密码
# mysql –uroot mysql> set password = password(‘123456‘); Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
|
到这里数据库安装就完成了
感谢各位大拿的blog。参考链接
http://www.aiezu.com/db/mysql_cant_connect_through_socket.html
http://blog.csdn.net/xiagege3/article/details/41852895
http://blog.csdn.net/hengrjgc/article/details/40299213
http://wilr.iteye.com/blog/2168659
http://www.cnblogs.com/xiongpq/p/3384681.html
http://msnvip.iteye.com/blog/542004
http://blog.sina.com.cn/s/blog_637e04c9010117ri.html
http://www.cnblogs.com/fuhj02/p/3541173.html
本文出自 “程子” 博客,请务必保留此出处http://jif521.blog.51cto.com/848361/1597899
Centos 7 源码编译安装mysql 5.6.22(整理篇)
标签:mysql linux
原文地址:http://jif521.blog.51cto.com/848361/1597899