wget https://downloads.mysql.com/archives/get/file/mysql-5.7.16.tar.gz
cmake的时候还需要依赖 https://downloads.mysql.com/archives/get/file/mysql-boost-5.7.16.tar.gz
安装mysql,结果发现新版需要cmake,万幸,我的环境没有cmake,草。
先安装cmake吧,之前我记得安装过,百度一下,下载之前的安装包。 tar zxvf http://distfiles.macports.org/cmake/cmake-2.8.12.2.tar.gz ./bootstrap make make install
安装到make install这一步,估计是因为需要root权限吧
[ 2%] Built target cmIML_test [ 5%] Built target cmsys [ 5%] Built target cmsysTestDynload [ 6%] Built target cmsys_c [ 7%] Built target cmsysTestProcess [ 7%] Built target cmsysTestSharedForward [ 8%] Built target cmsysTestsC [ 10%] Built target cmsysTestsCxx [ 12%] Built target cmzlib [ 24%] Built target cmcurl [ 24%] Built target LIBCURL [ 25%] Built target cmcompress [ 26%] Built target cmbzip2 [ 47%] Built target cmlibarchive [ 48%] Built target cmexpat [ 56%] Built target cmForm [ 79%] Built target CMakeLib [ 83%] Built target CPackLib [ 92%] Built target CTestLib [ 95%] Built target ccmake [ 95%] Built target cmake [ 95%] Built target cpack [ 96%] Built target ctest [ 97%] Built target documentation [ 98%] Built target CMakeLibTests [ 99%] Built target runcompilecommands [ 99%] Built target foo [ 99%] Built target memcheck_fail [ 99%] Built target pseudo_BC [ 99%] Built target pseudo_purify [100%] Built target pseudo_valgrind [100%] Built target pseudonl_BC [100%] Built target pseudonl_purify [100%] Built target pseudonl_valgrind Install the project... -- Install configuration: "" CMake Error at cmake_install.cmake:36 (FILE): file cannot create directory: /usr/local/doc/cmake-2.8. Maybe need administrative privileges.
make: *** [install] 错误 1
没事儿,据说CMake 可以在编译目录下运行,所以用的时候直接bin/cmake
/home/pay/local/cmake-2.8.12.2/bin/cmake . -DCMAKE_INSTALL_PREFIX=/home/pay/local/mysql56 \ -DSYSCONFDIR=/home/pay/local/mysql56 \ -DMYSQL_DATADIR=/home/pay/local/mysql56/data \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DMYSQL_UNIX_ADDR=/home/pay/local/mysql56/tmp/mysql.sock \ -DMYSQL_USER=mysql
//设置目录所有者及所属组 chown -R pay:pay /home/pay/local/mysql56/ mkdir /home/pay/local/mysql56/data/ chown -R pay:pay /home/pay/local/mysql56/data/
//对数据库进行初始化 (高版本的5.7换成了mysqld --intialize,具体看错误提示) /home/pay/local/mysql56/scripts/mysql_install_db --basedir=/home/pay/local/mysql56 --datadir=/home/pay/local/mysql56/data --user=pay --defaults-file=/home/pay/local/mysql56/my.cnf --explicit_defaults_for_timestamp
卧槽,FATAL ERROR: Could not find ./bin/my_print_defaults
主要看提示,人家说你是不是没make install啊,还真是,于是make install
//启动 sudo /Users/wenzg/local/mysql/bin/mysqld_safe --defaults-file=/Users/wenzg/local/mysql/my.cnf --pid-file=/Users/wenzg/local/mysql/data/local-dev.pid --user=mysql
注:如果端口冲突,可以在my.cnf里面改下端口
//检查服务是否启动 //查看进程 ps -le | grep mysqld //查看端口 netstat -na | grep 3306 //查看服务器版本
/home/pay/local/mysql56/bin/mysqladmin version
//设置管理员密码
/home/pay/local/mysql56/bin/mysql -u root
这里高版本的mysql5.7在启动时需要添加参数--skip-grant-tables,这样才能以root无密码方式登陆进去,添加密码后再重启mysql服务
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root'; flush privileges;
5.7版本mysql.user表已经木有了password字段,改成了authentication_string,而且首次安装后授权的用户需要update授权表,不能grant命令,update mysql.user set authentication_string=PASSWORD("root") where user='root' and Host = 'localhost';
下面是对于mysql的简单设置,主要是开启常规日志、慢查询日志
# These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... port = 7777 socket = /home/pay/local/mysql56/tmp/mysql.sock
#慢查询配置 slow_query_log = 'ON' slow_query_log_file = '/home/pay/local/mysql56/data/slow_query.log' long_query_time = 1
#日志配置 general_log = 'ON' general_log_file = '/home/pay/local/mysql56/data/mysql.log'
PS:这里日志如果被rm,自己手动touch的日志是不会生效的,需要在console中flush logs,会重新生成日志文件
#设置默认连接编码 character_set_server=latin1