1、安装依赖
在安装mysql之前需要安装的依赖有make、bison、gcc-c++、cmake、ncurses 以上下载地址如下: make编译器下载地址:gnu.org/software/make/ bison下载地址:gnu.org/software/bison/ gcc-c++下载地址:gnu.org/software/gcc/ cmake下载地址:cmake.org/ ncurses下载地址:gnu.org/software/ncurses/ 如果以上依赖已安装则可以忽略2、下载mysql5.6
下载地址:dev.mysql/ ;下载之后解压 tar -xvzf mysql-5.6.12.tar.gz
3、为mysql创建独立用户
groupadd mysql
#增加一个名为 mysql的用户。
useradd mysql -g mysql -M -s /sbin/nologin
-g:指定新用户所属的用户组(group)
-M:不建立根目录
-s:定义其使用的shell,/sbin/nologin代表用户不能登录系统。
# 新增的用户名不一定就得叫“mysql”也可以叫其他的,在安装的时候就要指定你创建的用户就OK了
4、给mysql安装目录和数据目录授权
如果mysql的时间安装目录不在/usr/local/mysql 则需要创建一个软连接 ln -s 实际地址 /usr/local/mysql # cd /usr/local/mysql # chown -R mysql:mysql . (#这里最后是有个.的大家要注意# 为了安全安装完成后请修改权限给root用户) # scripts/mysql_install_db --user=mysql (先进行这一步再做如下权限的修改) # chown -R root:mysql . (将权限设置给root用户,并设置给mysql组, 取消其他用户的读写执行权限,仅留给mysql "rx"读执行权限,其他用户无任何权限) # chown -R mysql:mysql ./data (数据库存放目录设置成mysql用户mysql组) # chmod -R ug+rwx . (赋予读写执行权限,其他用户权限一律删除仅给mysql用户权限)
5、添加mysql默认配置文件my.cnf
下面的命令是将mysql的配置文件拷贝到/etc
# cp support-files/my-default.cnf /etc/my.cnf
my.cnf 基本配置如下:
# For advice on how to change settings please see # dev.mysql/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] bind-address = 0.0.0.0 #不区大写 lower_case_table_names = 1 # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... port = 3307 # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
6、启动mysql
1、bin/mysqld_safe --user=mysql &检查是否启动成功:
ps -ef | grep mysqlnetstat -tnl|grep 3307
2、脚本启动
将mysql的启动服务添加到系统服务中# cp support-files/mysql.server /etc/init.d/mysql现在可以使用下面的命令启动mysql# service mysql start停止mysql服务# service mysql stop重启mysql服务# service mysql restart
7、修改root密码
./bin/mysqladmin -u root password
8、开通外网访问权限
grant all privileges on *.* to root@"%" identified by "密码" with grant option;OK mysql已经安装好了