1、下载源码包 #wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.17.tar.gz 2、进入解压目录
cd mysql-5.7.17
3、安装相关依赖 [root@safehourse69 mysql-5.7.17]# yum install -y cmake gcc-c++* make ncurses-devel 2、4、创建mysql运行用户 [root@safehourse69 mysql-5.7.18]# useradd -M -s /sbin/nologin mysql 5、执行源码编译 #cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL-USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost 3、编译之后,下面就是安装了,执行如下命令 #make -j 4 && make install 在编译的时候,如果虚拟机或是机器配置过低会报如下错误,建议配置为4核4G的配置来安装,我的安装是卡到75%这里,然后就不动了 cc1plus: warning: unrecognized command line option "-Wno-unused-local-typedefs" 调整完配置之后,再执行上面的安装命令 #make -j 4 && make install 7、更改文件夹属主和属组
chown -R mysql.mysql /usr/local/mysql/
8、手动添加编辑配置文件 [root@safehourse69 mysql-5.7.18]# cd /usr/local/mysql/support-files/ [root@safehourse69 support-files]# vim my-default.cnf [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 socket = /tmp/mysql.sock character-set-server=utf8 back_log = 300 max_connections = 3000 max_connect_errors = 50 table_open_cache = 4096 max_allowed_packet = 32M #binlog_cache_size = 4M max_heap_table_size = 128M read_rnd_buffer_size = 16M sort_buffer_size = 16M join_buffer_size = 16M thread_cache_size = 16 query_cache_size = 128M query_cache_limit = 4M ft_min_word_len = 8 thread_stack = 512K transaction_isolation = REPEATABLE-READ tmp_table_size = 128M #log-bin=mysql-bin long_query_time = 6 server_id=1 innodb_buffer_pool_size = 1G innodb_thread_concurrency = 16 innodb_log_buffer_size = 16M innodb_log_file_size = 512M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 innodb_file_per_table = on [mysqldump] quick max_allowed_packet = 32M [mysql] no-auto-rehash default-character-set=utf8 safe-updates [myisamchk] key_buffer = 16M sort_buffer_size = 16M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] open-files-limit = 8192 [client] 9、初始化mysql服务
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
10、复制配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
11、复制启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
12、修改启动脚本,在下面这个位置后面写上安装路径
vim /etc/init.d/mysqld
basedir=/usr/local/mysql datadir=/usr/local/mysql/data
13、启动mysql 服务
cd /usr/local/mysql/bin/
./mysqld_safe --user=mysql &
service mysqld restart
Shutting down MySQL. SUCCESS! Starting MySQL. SUCCESS!
14 做软连接,让系统直接调用
ln -s /usr/local/mysql/bin/* /bin/
15、登录数据库报如下错误,卡到这里了 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
系统没有找到mysql.sock文件
这里查看配置文件里写的是mysqld.sock 把配置文件里的mysqld.sock改成mysql.sock重启mysql 服务,就可以登录了
默认没有密码直接登录的
mysql
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
16、登录数据库修改密码 mysql> SET PASSWORD = PASSWORD('Xinwangai7/'); Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
测试用新密码登录
mysql -u root -p
Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.18 Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>