下载和解压
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.44.tar.gz && tar -zxf mysql-boost-5.7.44.tar.gz && cd mysql-5.7.44
安装依赖
sudo apt install build-essential cmake bison libncurses5-dev pkg-config libssl-dev screen -y
配置
cmake . -DWITH_BOOST=./boost/ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DDEFAULT_COLLATION=utf8_general_ci
DWITH_BOOST
boost 库文件目录DCMAKE_INSTALL_PREFIX
安装位置DMYSQL_TCP_PORT
通讯端口DDEFAULT_CHARSET
默认字符DWITH_INNOBASE_STORAGE_ENGINE
开启 INNDBDMYSQL_DATADIR
数据目录DSYSCONFDIR
配置目录DDEFAULT_COLLATION
默认排序方式DWITH_READLINE
tab 补全等
开始编译和安装
make && make install
创建 mysql 用户
groupadd mysql && useradd -r -g mysql -s /bin/false mysql && mkdir mysql /usr/local/mysql/data && chown -R mysql:mysql /usr/local/mysql/data
-r
建立系统账号-s /bin/false
不能登录的账号-g
设置用户组
初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
执行成功之后显示密码的 [Note] A temporary password is generated for root@localhost: 初始密码
启动服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && systemctl enable mysqld && systemctl restart mysqld && systemctl status mysqld
登录数据库
/usr/local/mysql/bin/mysql -u root -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '要修改的密码';
导入备份
mysql -u root -p 数据库名称
导出备份
mysqldump -u root -p 数据库名称 > sql 文件路径
创建用户和权限设置
授权特定 ip 连接
CREATE ALL PRIVILEGES ON *.* TO '用户名'@'ip 地址' identified by '密码';
创建用户
CREATE USER '用户名'@'localhost' IDENTIFIED BY '密码';
用户权限
GRANT ALL PRIVILEGES ON 数据库名称.* TO '用户名'@'localhost';
应用权限
flush privileges;
正文完