yum -y install wget gcc-c++ cmake make bison ncurses-devel perl unzip添加MySQL系统用户 useradd -M -s /sbin/nologin mysql提前建立好相关目录 mkdir /data/mysql下载MySQL源代码 wget http://www.cmake.org/files/v2.8/cmake-2.8.11.2.tar.gz wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz安装cmake tar xzf cmake-2.8.11.2.tar.gz cd cmake-2.8.11.2 ./configure make && make install cd ..安装MySQL tar zxf mysql-5.6.13.tar.gz cd mysql-5.6.13 cmake . -DCMAKE_INSTALL_PREFIX=$db_install_dir \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DMYSQL_DATADIR=$db_data_dir \ -DSYSCONFDIR=/etc \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -DWITH_BIG_TABLES=1 \ -DWITH_DEBUG=0 make && make installcmake编译参数参考:https://linuxeye.com/Linux/MySQL-cmake-options.html 配置开机自启动: /bin/cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld #CentOS chkconfig mysqld on update-rc.d mysqld defaults #UbuntuMySQL配置文件/etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /data/mysql pid-file = /data/mysql/mysql.pid character-set-server = utf8 collation-server = utf8_general_ci user = mysql port = 3306 default_storage_engine = InnoDB innodb_file_per_table = 1 server_id = 1 log_bin = mysql-bin binlog_format = mixed expire_logs_days = 7 bind-address = 0.0.0.0 # name-resolve skip-name-resolve skip-host-cache #lower_case_table_names = 1 ft_min_word_len = 1 query_cache_size = 64M query_cache_type = 1 skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M # LOG log_error = /data/mysql/mysql-error.log long_query_time = 1 slow_query_log slow_query_log_file = /data/mysql/mysql-slow.log # Oher #max_connections = 1000 open_files_limit = 65535 [client] port = 3306初始化数据库 /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql chown mysql.mysql -R /data/mysql添加环境变量 echo "export PATH=\$PATH:/usr/local/mysql/bin" >> /etc/profile source /etc/profile安全设置(设定初始密码,移除匿名用户,移除测试数据库): 方式一(执行脚本): /usr/local/mysql/bin/mysql_secure_installation方式二(手工删除): /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"dbrootpwd\" with grant option;" /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"dbrootpwd\" with grant option;" /usr/local/mysql/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';" /usr/local/mysql/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';" /usr/local/mysql/bin/mysql -uroot -p$dbrootpwd -e "drop database test;" /usr/local/mysql/bin/mysql -uroot -p$dbrootpwd -e "reset master;"启动MySQL service mysqld start如果报错请查看日志/data/mysql/mysql-error.log 参考:lnmp中Install_MySQL函数部分 转载请保留固定链接: https://linuxeye.com/database/1907.html |