十、安装mysql(mysql-5.7.13)
1、到mysql官网获取下载地址:
选择linux通用版:
下载链接:
http://photo.blog.sina.com.cn/showpic.html#blogid=&url=http://album.sina.com.cn/pic/005ThHMyzy73B8R2AzJ37
2、下载:
cd /home/src wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
3、安装:
指定路径:
下载文件所在路径:/home/src
mysql安装路径:、/usr/local/mysql
mysql数据库保存路径:/etc/mysql
日志保存路径:/etc/log/mysql
mkdir /etc/mysql cd /home/src tar zxvf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz --解压完就是一个免安装的mysql目录了 mv mysql-5.7.13-linux-glibc2.5-x86_64 /usr/local/mysql --移动位置并重新命名为mysql groupadd mysql 新建mysql组: useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql ---新建msyql用户禁止登录shell
改变目录所有者:
cd /usr/local/mysql chown –R mysql . chgrp –R mysql . chown -R mysql /etc/mysql
配置参数:
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/etc/mysql
注意:若出错:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:
yum install libaio
注意:执行完会显示:A temportary password is generated for root@localhost:B/oiqs%,M2N*这个是临时密码,记录下来后面有用
bin/mysql_ssl_rsa_setup --datadir=/etc/mysql
修改系统配置文件:
cp support-files/my-default.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysql
配置/etc/init.d/mysql文件:
vim /etc/init.d/mysql
修改下面内容:
basedir=/usr/local/mysql datadir=/etc/mysql
配置my.cnf文件:
vim /etc/my.cnf [client] port = 3306 # 设置mysql客户端连接服务端时默认使用的端口 socket = /usr/local/mysql/mysql.sock default-character-set = utf8 # 设置mysql客户端默认字符集 #character-set-server = utf8 #这里会报错,用上面那条代替 [mysql] no-auto-rehash [mysqld] port = 3306 #mysql服务端默认监听的TCP/IP端口 socket = /usr/local/mysql/mysql.sock basedir = /usr/local/mysql # 基准路径,其他路径都相对于这个路径 max_allowed_packet = 32M datadir = /etc/mysql # mysql数据库文件所在目录 explicit_defaults_for_timestamp = true skip-ssl secure-file-priv = NULL lower_case_table_names = 1 back_log = 300 max_connections = 3000 max_connect_errors = 100 table_open_cache = 4096 external-locking = FALSE sort_buffer_size = 16M join_buffer_size = 16M thread_cache_size = 16M query_cache_size = 128M query_cache_limit = 4M ft_min_word_len = 8 thread_stack = 512K transaction_isolation = REPEATABLE-READ tmp_table_size = 128M max_heap_table_size = 128M long_query_time = 6 slow_query_log slow_query_log_file = /etc/log/mysql/slow.log [mysqldump] quick max_allowed_packet = 32M [mysqld_safe] open-files-limit = 8192 log-error = /etc/log/mysql/mysql_3306.err
查看/etc/log/mysql/mysql_3306.err 下是否存在此文件,如不存在则创建文件,并开启此文件的读写权限
#这里的mysql_3306.err文件要chown mysql /etc/log/mysql/mysql_3306.err 更改属主,否则无法启动
chown mysql /etc/log/mysql/mysql_3306.err 启动mysql:bin/mysqld_safe --user=mysql & //在后台挂起 登陆mysql:bin/mysql --user=root –p 输入之前的临时密码 mysql> set password=password('123');//修改root密码为123 mysql>grant all privileges on *.* to root@'%' identified by '123';//所有ip都能远程访问该服务器上的mysql数据库 mysql> flush privileges;//生效 退出mysql:quit;
把mysql的命令配置到系统环境变量中,以后调用不用写路径:
vim /etc/profile 最后一行加:export PATH=/usr/local/mysql/bin:$PATH source /etc/profile //使修改生效
配置mysql开机启动:
chmod 755 /etc/init.d/mysql
注意:切记开启服务器的端口号3306,否者会无法连接
林外听秋风