朝花夕拾:linux CentOS 7 安装mysql 5.7.13
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了朝花夕拾:linux CentOS 7 安装mysql 5.7.13相关的知识,希望对你有一定的参考价值。
1.安装环境:
[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
mysql版本号:mysql-5.7.13-linux-glibc2.5-x86_64.tar
各项配置路径:
安装文件下载目录:/data/software (软件包所在位置)
Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql
日志保存位置:/data/log/mysql
2.本人百度云盘分享,下载mysql
https://pan.baidu.com/s/1nuEypO9
3.安装主要步骤:
# rpm -qa |grep -i mariadb # rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
执行如下命名:
# mkdir -p /data/software # mkdir -p /data/log/mysql # cd /data/software #(上传安装包)
通过xftp或 rz命令 上传mysql安装包。
# cd /usr/local # tar -xvf /data/software/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz # mv mysql-5.7.13-linux-glibc2.5-x86_64 mysql # echo $? 0 # ll -h 总用量 0 drwxr-xr-x. 2 root root 6 11月 5 2016 bin drwxr-xr-x. 2 root root 6 11月 5 2016 etc drwxr-xr-x. 2 root root 6 11月 5 2016 games drwxr-xr-x. 2 root root 6 11月 5 2016 include drwxr-xr-x. 2 root root 6 11月 5 2016 lib drwxr-xr-x. 2 root root 6 11月 5 2016 lib64 drwxr-xr-x. 2 root root 6 11月 5 2016 libexec drwxr-xr-x. 9 7161 wheel 129 5月 25 2016 mysql-5.7.13-linux-glibc2.5-x86_64 drwxr-xr-x. 2 root root 6 11月 5 2016 sbin drwxr-xr-x. 5 root root 49 8月 23 00:39 share drwxr-xr-x. 2 root root 6 11月 5 2016 src # mkdir -p /data/mysql #创建数据仓库目录 # groupadd mysql ---新建一个msyql组 # useradd -r -s ---新建msyql用户,禁止登录shell # cd /usr/local/mysql # chown -R mysql . # chgrp -R mysql . # chown -R mysql /data/mysql # cd /usr/local/mysql # bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #初始化mysql,记住初始mysql密码 # Touch mysql.error # bin/mysql_ssl_rsa_setup --datadir=/data/mysql # cd support-files/ # cp my-default.cnf /etc/my.cnf # cp mysql.server /etc/init.d/mysql
# vi /etc/init.d/mysql
将空白的basedir和datadir修改为以下配置:
basedir=/usr/local/mysql datadir=/data/mysql
# vi /etc/my.cnf
修改为以下内容:
[client] port = 3306 socket = /opt/mysql/mysql.sock #character_set_server=utf8 default-character-set=utf8 [mysql] no-auto-rehash [mysqld] #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER sql_mode='' #default-character-set=utf8 socket = /opt/mysql/mysql.sock basedir = /opt/mysql max_allowed_packet = 32M datadir = /data/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 max_allowed_packet = 32M sort_buffer_size = 128M join_buffer_size = 128M explicit_defaults_for_timestamp = true thread_cache_size = 100 query_cache_size = 256M 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 #slow_query_log slow_query_log_file = /data/log/mysql/slow.log character-set-server=utf8 server_id =1 log-bin=mysqlbin-log long_query_time = 3 slow_query_log = on innodb_buffer_pool_size = 1287M innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 32M innodb_log_file_size = 512M innodb_log_files_in_group = 2 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 binlog_format = ROW audit_json_file=on #保证mysql重启后自动启动插件 plugin-load=AUDIT=libaudit_plugin.so #防止删除了插件,重启后又会加载 audit_record_cmds='delete,update,create,drop,alter,grant,truncate' #要记录哪些命令语句,因为默认记录所有操作; [mysqldump] quick max_allowed_packet = 32M [mysqld_safe] open-files-limit = 8192 log-error = /data/log/mysql/mysql_3306.err
以上为my.cnf中的内容
# cd /usr/local/mysql # mkdir data # chown -R mysql . # chgrp -R mysql . # bin/mysqld_safe --user=mysql & (执行后,ps –ef|grep mysql,可以看到mysql的进程) # bin/mysqld_safe --skip-grant-tables --user=mysql & (后台启动mysql,且忘记mysql密码时使用) # bin/mysql --user=root -p
--输入第6步生成的临时密码
修改mysqlroot用户密码:
Mysql>set password for 'root'@'localhost' =password('redhat'); mysql>update mysql.user set authentication_string=password('redhat') where user='root'; mysql>grant all privileges on *.* to [email protected]'%' identified by 'redhat'; mysql> flush privileges; mysql> use mysql; mysql> select host,user from mysql.user;
# vi /etc/profile # 添加mysql系统路径
添加:
export PATH=/usr/local/mysql/bin:$PATH
# source /etc/profile #导入配置 # chmod 755 /etc/init.d/mysql # 配置mysql自动启动 # chkconfig --add mysql #配置mysql自动启动 # chkconfig --level 345 mysql on #配置mysql自动启动
登录mysql:
# bin/mysql --user=root -p
至此mysql安装完成。
总结:
这种方式安装的mysql,
# systemctl stauts/start/stop mysql.service
等操作不起作用。
但
#service mysql status/stop
可以运行;
但是service mysql start 不能启动,需要用:# bin/mysqld_safe --user=mysql & 才能启动
以上是关于朝花夕拾:linux CentOS 7 安装mysql 5.7.13的主要内容,如果未能解决你的问题,请参考以下文章