一、编译
1、源码下载地址:
https://downloads.mysql.com/archives/community/
2、安装cmake
3、把源码里的boost放到/usr/local下面
4、mkdir bld;cd bld
5、cmake .. -DWITH_BOOST=/usr/local/boost
cmake过程会提示确各种库,缺啥补啥。
6、make;make install
可以用make -j 4多线程编译。
7、make package
,可以把编译好的MySQL二进制文件生成一个二进制文件压缩包,可直接安装到其他服务器上
二、使用
1、初始化
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql/
或者
mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql/
初始化会生成临时密码,如果忘了,可以先用无密码登录再改密码
cp support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start(service mysqld start)
2、无密码登录
service mysqld stop
./mysqld_safe --skip-grant-tables
3、允许远程登录
mysql -u root -p
use mysql
select host, user, authentication_string, plugin from user;
update user set host='%' where user='root';
flush privileges;
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;
update mysql.user set password=password('1111') where user='root';
navite连接可能需要修改认证方式
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '111111';
update user set authentication_string=password('123456'), plugin = 'mysql_native_password' where user = 'root';(仅供参考)
4、配置文件my.cnf
mysql --help|grep "my.cnf"可以查看默认配置文件路径
一般是/etc/my.cnf /etc/mysql/my.cnf
[mysqld]
bind-address = 0.0.0.0
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
server-id = 1
log-bin=mysql-bin