教你使用源码安装Mysql数据库
1.1关闭防火墙 #systemctl stop firewalld.service //停止firewall #systemctl disable firewalld.service //禁止firewall开机启动 #firewall-cmd --state //查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
1.2 检查是否安装NySQL,如果安装 卸载之 #rpm -qa |grep mysql #yum remove mysql*
1.3 检查是否安装MariaDB,如果安装 卸载之(重要) #rpm -qa |grep mariadb #yum remove mariadb*
1.4 新增用户/组 参数文件 #groupadd mysql #useradd -d /home/mysql -g mysql -m mysql #passwd mysql#vi ~/.bash_profile# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/MySQL/bin export PATH#source ~/.bash_profile
1.5 mysql数据库的二进制安装
1.5.1下载数据库#mkdir /opt #cd /apt
打开mysql软件网址https://downloads.mysql.com/archives/community/,选择linux-Generic版本下载#wget https://downloads.mysql.com/archives/get/file/mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz
安装依赖包#yum install libaio* libncur* libstd* ncurses* -y #tar -zxf mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz #ln -s /opt/mysql-5.6.27-linux-glibc2.5-x86_64 /opt/mysql
创建相关文件目录#mkdir -p /opt/mysql/{data,sock,binlog,slowlog,pid,errlog} #chown -R mysql:mysql /opt/mysql //修改权限链接 #chown -R mysql:mysql /opt/mysql/ //修改目录权限
配置/etc/my.cnf#vim /etc/my.cnf[mysqld] basedir=/opt/mysql datadir=/opt/mysql/data port=3306 pid-file = /opt/mysql/pid/mysql.pid user = mysql socket=/opt/mysql/sock/mysql.sock bind-address = 0.0.0.0 server-id = 1 character-set-server = utf8 max_connections = 1000 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 128 max_allowed_packet = 4M binlog_cache_size = 1M max_heap_table_size = 8M tmp_table_size = 16M read_buffer_size = 2M read_rnd_buffer_size = 8M sort_buffer_size = 8M join_buffer_size = 8M key_buffer_size = 4M thread_cache_size = 8 query_cache_type = 1 query_cache_size = 8M query_cache_limit = 2M ft_min_word_len = 4 log-bin =/opt/mysql/binlog/mysql-bin binlog_format = mixed expire_logs_days = 30 log_error = /opt/mysql/errlog/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /opt/mysql/slowlog/mysql-slow.log performance_schema = 0 explicit_defaults_for_timestamp #lower_case_table_names = 1 skip-external-locking default_storage_engine = InnoDB #default-storage-engine = MyISAM innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 64M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 #lower_case_table_names = 1 skip-external-locking default_storage_engine = InnoDB #default-storage-engine = MyISAM innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 64M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [client] port=3306 socket=/opt/mysql/sock/mysql.sock [mysql] socket=/opt/mysql/sock/mysql.sock
初始化数据库#/opt/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql
将启动脚本加入init.d下#cp -rp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
启动数据库#/etc/init.d/mysqld start
配置mysql命令的全局使用路径#echo "export PATH=/opt/mysql/bin:$PATH" >> /etc/profile #source /etc/profile
管理员密码#mysqladmin -u root password