linux安装mysql

linux安装mysql

  • 解压
  • 修改配置文件
  • 初始化
  • 启动服务
  • 修改密码
  • 远程登录

解压

# 解压
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

# 移动
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql

# 创建记录文件夹
mkdir -p /usr/local/mysql/data

# 建用户
useradd -m mysql

# 修改所属和权限
chmod -R 755 /usr/local/mysql
chown -R msyql:mysql /usr/local/mysql

修改配置文件

  • vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

初始化

# 环境变量
echo 'export MYSQL_HOME=/usr/local/mysql' >> /etc/profile
echo 'export PATH=$PATH:$MYSQL_HOME/bin' >> /etc/profile

# 初始化
mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --initialize

# 查看密码
cat $MYSQL_HOME/mysql.err | awk -F 'root@localhost:' '{print $2}' 

启动服务

# 添加软连接
ln -s $MYSQL_HOME/support-files/mysql.server /etc/init.d/mysql
ln -s $MYSQL_HOME/bin/mysql /usr/bin/mysql

# 启动
$MYSQL_HOME/support-files/mysql.server start
# service mysql start

修改密码

  • mysql -u root -p
-- 修改密码
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

-- 开启远程访问
update mysql.user set host = '%' where user = 'root';

-- 刷新权限
flush privileges;

远程登录

mysql -h 10.10.10.81 -P 3306 -u root -p123

你可能感兴趣的:(Linux)