下载软件包
cd /usr/local/src
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
#创建用户
useradd -s /sbin/nologin mysql
安装
tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql
#初始化mysql, 这儿会给出一个密码,不能丢失,后续有用
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
初始化问题解决
安装时出现error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
错误
yum install -y libaio #安装后在初始化就OK了
安装后操作
chown -R root:root /usr/local/mysql/
chown -R mysql:mysql /usr/local/mysql/data/
vi /etc/my.cnf
[mysqld]
port=3306
basedir=/usr/local/mysql #mysql服务安装地址
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/tmp/mysql.sock
user=root
max_connections=151
#指定客户端连接mysql时的socket通信文件路径
[client]
socket=/usr/local/mysql/tmp/mysql.sock
mkdir /usr/local/mysql/tmp
chmod 777 /usr/local/mysql/tmp
--将mysql服务添加到/etc/init.d
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
--添加服务
chkconfig --add mysql
--查看是否添加成功
chkconfig --list mysql
启动服务
systemctl start mysql || service mysql start
添加环境变量
vi /etc/profile
末尾添加
export PATH=$PATH:/usr/local/data/mysql/bin:/usr/local/mysql/lib
加载自定义环境变量
source /etc/profile
修改密码
mysql -uroot -p 密码是初始化时的密码
alter user 'root'@'localhost' identified by 'root';
网友评论