1、准备数据存放的文件系统:
新建一个逻辑卷(过程见链接),并将其挂载至/mydata/data目录, 做为mysql数据的存放目录。
http://858004880.blog.51cto.com/7265424/1759317
2、新建用户以安全方式运行进程:
1.删除系统原来的mysql用户家目录 [root@web ~]# userdel -rmysql 2.创建mysql系统用户组 [root@web ~]# groupadd -r mysql 3.添加mysql用户到mysql组并且指明路径 [root@web ~]# useradd -g mysql -r -s/sbin/nologin -M -d /mydata/data mysql useradd[options] LOGIN -g GID:指明用户所属基本组,可为组名,也可以GID; -d/PATH/TO/HOME_DIR: 以指定的路径为家目录; -s SHELL: 指明用户的默认shell程序,可用列表在/etc/shells文件中; -r: 创建系统用户 -M: 不自动创建用户的家目录 [root@web ~]# tail -2 /etc/passwd mysql:x:498:499::/mydata/data:/sbin/nologin 4.修改数据文件属主: [root@web ~]# chown -R mysql:mysql/mydata/data/ [root@web ~]# ll /mydata/ total 4 drwxr-xr-x3 mysql mysql 4096 Apr 1 16:21 data
3、安装并初始化mysql-5.6.29
3.1.安装所需要的 gccgcc-c++ ncurses-devel perl库:
[root@web tools]# yum -y install gcc gcc-c++ ncurses-devel perl
3.2.安装cmrk
[root@web tools]# wget https://cmake.org/files/v3.5/cmake-3.5.0.tar.gz [root@web tools]# tar xf cmake-3.5.0.tar.gz [root@web tools]# cd cmake-3.5.0 [root@web cmake-3.5.0]# ./bootstrap [root@webcmake-3.5.0]# gmake && gmake install
3.3.下载解压mysql5.5:
[root@web tools]# wget http://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.48.tar.gz [root@webtool]# tar xf mysql-5.5.48.tar.gz.1
3.4.编译安装:
[root@web tool]# cdmysql-5.5.48 [root@webmysql-5.5.48]# cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/mydata/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock\ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci
# make&& make install
3.5.修改mysql目录所有者和组
[root@web mysql-5.5.48]# cd /usr/local/mysql/ [root@webmysql]# chown -R mysql:mysql .
3.6.初始化mysql数据库
# scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/mydata/data --user=mysql
3.7.为mysql提供主配置文件my.cnf:
[root@web mysql]# cp support-files/my-large.cnf/etc/my.cnf
3.8.修改my.cnf
修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data
[root@web mysql]# vim /etc/my.cnf [mysqld] # Try number of CPU's*2 for thread_concurrency thread_concurrency = 2 datadir = /mydata/data innodb_file_per_table = 1 skip_name_resolve = 1
3.9.为mysql提供sysv服务脚本:
[root@web mysql]# cpsupport-files/mysql.server /etc/rc.d/init.d/mysqld [root@webmysql]# chmod +x /etc/rc.d/init.d/mysqld
3.10.添加至服务列表:
[root@web mysql]# chkconfig --add mysqld [root@webmysql]# chkconfig mysqld on
3.11.输出mysql的man手册至man命令的查找路径:
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
编辑/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
[root@web mysql]# vim /etc/man.config #/var/cache/man/.../[locale/]catx/page.x. # The keyword FHSwill cause this behaviour (and overrides FSSTND). # Explicitly givencatdirs override. # # FSSTND FHS # # This file is alsoread by man in order to find how to call nroff, less, etc., # and to determinethe correspondence between extensions and decompressors. # # MANBIN /usr/local/bin/man # # Every automaticallygenerated MANPATH includes these fields # MANPATH /usr/man MANPATH /usr/share/man MANPATH /usr/local/man MANPATH /usr/local/share/man MANPATH /usr/X11R6/man MANPATH/usr/local/mysql/man
3.12.输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:
# ln -sv /usr/local/mysql/include /usr/include/mysql
3.13.输出mysql的库文件给系统库查找路径:
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
3.14.让系统重新载入系统库:
# ldconfig
3.15.修改PATH环境变量:
编辑/etc/profile,在最后添加:
[root@web mysql]# vim /etc/profile PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH
保存退出;然后执行:
[root@web mysql]# source/etc/profile
环境变量添加成功
3.16. 启动mysql
[root@web mysql]# service mysqld start
3.17.输入mysql命令:
[root@web mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.48-log Source distribution Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved. Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarks of theirrespective owners. Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement. mysql>
mysql默认为空密码!
3.18. 修改MySQL用户root的密码
# 修改密码为test123: mysql> SET PASSWORD FOR'root'@'localhost' = PASSWORD('test123'); Query OK, 0 rows affected(0.00 sec) mysql> SET PASSWORD FOR'root'@'127.0.0.1' = PASSWORD('test123'); Query OK, 0 rows affected(0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected(0.00 sec) # 登录: [root@web html]#mysql -uroot -p Enter password: Welcome to the MySQLmonitor. Commands end with ; or \g. Your MySQLconnection id is 3 Server version:5.5.48-log Source distribution Copyright (c) 2000,2016, Oracle and/or its affiliates. All rights reserved. Oracle is aregistered trademark of Oracle Corporation and/or its affiliates. Othernames may be trademarks of their respective owners. Type 'help;' or '\h'for help. Type '\c' to clear the current input statement. mysql>
3.19. 优化mysql,清除无用的MySQL用户及库:
1.查看数据库: mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) 删除test库; mysql> drop database test; Query OK, 0 rows affected (0.03 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) 删除mysql库中无用的用户: mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | nginx.com | | root | nginx.com | +------+-----------+ 6 rows in set (0.00 sec) mysql> drop user root@"::1"; Query OK, 0 rows affected (0.02 sec) mysql> drop user ""@localhost; Query OK, 0 rows affected (0.00 sec) mysql> drop user root@nginx.com; Query OK, 0 rows affected (0.00 sec) mysql> drop user ""@nginx.com; Query OK, 0 rows affected (0.00 sec) 删除以上4个无用的用户,只保留2个root@127.0.0.1和root@localhost用户。 mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | localhost | +------+-----------+ 2 rows in set (0.00 sec) 注意:操作千万要细心,万一不小心删除了root@localhost这个用户,怎么办? 1.我们可以用root@127.0.0.1这个ip账号登录: [root@nginx ~]# mysql -h 127.0.0.1 -uroot-p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.5.48-log Sourcedistribution Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved. Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarksof their respective owners. Type 'help;' or '\h' for help. Type '\c' toclear the current input statement. 2.登录进来以后,再用grant命令来创建root@localhost用户,并且赋予root权限: mysql> grant all privileges on *.* to root@localhost identified by 'test123'; Query OK, 0 rows affected (0.03 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye 3.我们再root账号在本地进行登录 [root@nginx ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.5.48-log Sourcedistribution Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved. Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarksof their respective owners. Type 'help;' or '\h' for help. Type '\c' toclear the current input statement. 我们在本地用root账号成功登录! 4.查看用户: mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | localhost | +------+-----------+ 2 rows in set (0.00 sec) Root@localhost用户已经添加进来了!
mysql-5.5编译安装成功!