Centos 7 安装 MySQL 5.6.tar.gz
一、下载 MySQL
1、官网下载:MySQL :: Download MySQL Community Server (Archived Versions)
2、卸载系统自带的 Mariadb
[root@localhost ~]# rpm -qa|grep mariadb // 查询出来已安装的 mariadb
[root@localhost ~]# rpm -e --nodeps 文件名 // 卸载 mariadb,文件名为上述命令查询出来的文件
3、删除 etc
目录下的 my.cnf
[root@localhost ~]# rm /etc/my.cnf
4、执行以下命令来创建 mysql 用户组
[root@localhost ~]# groupadd mysql
5、执行以下命令来创建一个用户名为 mysql 的用户并加入 mysql 用户组
[root@localhost ~]# useradd -g mysql mysql
6、将下载的压缩包放到 /usr/local/
目录下(通过 mv
要移动的文件 /usr/local/
)
7、解压安装包
[root@localhost local]# tar -xvf mysql-5.6.51-linux-glibc2.5-x86_64.tar
注:如果压缩包为: mysql-5.6.51-linux-glibc2.5-x86_64.tar.gz
,则解压命令为: tar -zxvf mysql-5.6.51-linux-glibc2.5-x86_64.tar.gz
8、将解压好的文件夹重命名为 mysql
[root@localhost local]# mv 解压出来的文件夹名 mysql
9、在 etc 下新建配置文件 my.cnf,并在该文件中添加一下代码,当然也有简单方式:直接 copy 一份 my.cnf 文件到 /etc 下,然后再修改即可,copy 一份 /usr/local/mysql/support-files/
下的 my-default.cnf
文件到 /etc
下
命令为:[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
然后,配置 /etc
目录下的 my.cnf
文件
[root@localhost support-files]# vim /etc/my.cnf
通过 vim 编辑器编辑 my.cnf
代码如下:
[root@localhost env]# cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # 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 ########basic settings######## #basedir = /usr datadir = /data/mysql port = 3306 # server_id = ..... socket = /data/mysql/mysql.sock log-error = /data/mysql/error.log pid-file = /data/mysql/mysql.pid user = mysql tmpdir = /tmp character_set_server = utf8 default-storage-engine = INNODB lower_case_table_name = 1 #log-queries-not-using-indexes skip-host-cache skip-name-resolve # skip-external-locking query_cache_size = 128M query_cache_type = 1 query_cache_limit = 4M query_cache_min_res_unit = 4K sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #performance_schema = 0 #explicit_defaults_for_timestamp #lower_case_table_names = 1 interactive_timeout = 28800 wait_timeout = 28800 default-time-zone = '+8:00' back_log = 500 max_connections = 3000 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 4096 binlog_cache_size = 1M max_heap_table_size = 256M tmp_table_size = 256M max_allowed_packet = 32M ########buffer settings######## read_buffer_size = 16M read_rnd_buffer_size = 64M sort_buffer_size = 32M join_buffer_size = 16M key_buffer_size = 128M thread_cache_size = 100 bulk_insert_buffer_size = 16M ########log settings######## #log_bin = mysql-bin #binlog_format = mixed #expire_logs_days = 30 slow_query_log=1 slow_query_log_file = /data/mysql/mysql-slow.log long_query_time = 1 min_examined_row_limit = 100 log_queries_not_using_indexes = 1 log_throttle_queries_not_using_indexes = 10 log-slow-admin-statements = 1 log_slow_slave_statements = 0 #log_timestamps=system log_output = FILE ########innodb settings######## innodb_file_per_table = 1 innodb_open_files = 2000 innodb_buffer_pool_size = 4G innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 8M innodb_log_file_size = 128M innodb_log_files_in_group = 2 innodb_max_dirty_pages_pct = 80 innodb_lock_wait_timeout = 50 innodb_flush_method = O_DIRECT # 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 [mysqldump] quick max_allowed_packet = 16M [client] default-character-set=utf8 socket = /data/mysql/mysql.sock
10、进入安装 mysql 软件目录
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# chown -R mysql:mysql ./ 修改当前目录拥有着为 mysql 用户
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql 安装数据库
注:若执行以上最后一个命令出现以下问题:
FATAL ERROR: please install the following Perl modules before executing
./scripts/mysql_install_db:Data::Dumper
解决方法 :安装 autoconf 库
命令: yum -y install autoconf
,此包安装时会安装 Data:Dumper 模块,安装完成重新执行上述最后一个命令
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql
[root@localhost mysql]# chown -R mysql:mysql data 修改当前 data 目录的拥有者为 mysql 用户
二、配置 MySQL
1、授予 my.cnf 最大权限
[root@localhost ~]# chmod 777 /etc/my.cnf
设置开机自启动服务控制脚本。
2、复制启动脚本到资源目录
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
3、增加 mysqld 服务控制脚本执行权限
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
4、将 mysqld 服务加入到系统服务
[root@localhost mysql]# chkconfig --add mysqld
5、检查 mysqld 服务是否已经生效
[root@localhost mysql]# chkconfig --list mysqld
命令输出类似下面的结果:
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
表明mysqld服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用 service 命令控制 mysql 的启动和停止
命令为: service mysqld start
和 service mysqld stop
6、启动 mysqld
[root@localhost mysql]# service mysqld start
7、将 mysql 的 bin 目录加入 PATH 环境变量,编辑 ~/.bash_profile
文件
[root@localhost mysql]# vim ~/.bash_profile
在文件最后添加如下信息:
export PATH=$PATH:/usr/local/mysql/bin
然后按 ESC 键,继续 shift 键加冒号打出来 :
,接下来输入 wq 回车即可,执行下面的命令是修改的内容立即生效:
[root@localhost mysql]# source ~/.bash_profile
8、以 root 账户登录 mysql 默认是没有密码的
[root@localhost mysql]# mysql -uroot -p
要输入密码的时候直接回车即可。
9、设置 root 账户密码为 root(也可以修改成你要的密码)
mysql>use mysql;
mysql>update user set password=password('root') where user='root' and host='localhost';
mysql>flush privileges;
10、设置远程主机登录,注意下面的 your username 和 your password 改成你需要设置的用户和密码
mysql>GRANT ALL PRIVILEGES ON *.* TO 'your username'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: 使用 Spring 框架能带来哪些好处?
下一篇: JavaScript 集合的方法
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论