Ubuntu 18.04 安装 mysql 8.0
进入 mysql 下载列表
https://dev.mysql.com/downloads/mysql/
第一步 下载源码(这里下的是 boost 版本)
cd /usr/local/src
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.18.tar.gz
第二步 编译安装
#安装依赖包
apt install build-essential cmake bison libncurses5-dev libssl-dev pkg-config
#make
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=boost -DFORCE_INSOURCE_BUILD=ON &
make && make install
第三步 添加用户
groupadd mysql
useradd -g mysql mysql
mkdir -p /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql
第四步 初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#这一步会打印输出随机生成的root账号初始密码ru。
第五步 配置
配置 my.cnf
vim /etc/my.cnf
# 然后写入以下内容 #
[client]
socket = /tmp/mysql.sock
[mysqld]
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
配置 服务项
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
update-rc.d mysqld defaults
service mysqld start
echo -e '# MySQL PATH\nexport PATH=/usr/local/mysql/bin:$PATH\n' >> /etc/profile
source /etc/profile
第六步 远程连接(可选)
mysql -uroot -p'Ej0cJ?VA<npl'
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; #更新一下用户的密码
FLUSH PRIVILEGES; #刷新权限
alter user 'root'@'%' identified by '123456';#重置密码,666666就是变更后的密码,自己的密码自己更改下哦
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql -uroot -hlocalhost -p'123456'
第六步 管理
systemctl start mysqld #
systemctl stop mysqld
systemctl restart mysqld
其他
内存1g以下的会在make的时候停止: linux 启用虚拟内存