Linux Mysql 安装
解压放入你想安装的目录,然后移动并改名
tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
mv -v mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
再创建用户和用户组
groupadd mysql
useradd -r -g mysql mysql
将安装目录所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql
在mysql目录下创建data文件夹
#mkdir data
初始化数据库
yum -y install numactl
yum search libaio
yum install libaio
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
完成初始化后编辑配置文件 /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
将mysql加入到服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
开机启动
chkconfig mysql on
启动mysql
service mysql start
设置mysql密码(因为在配置文件取消了密码验证,可以直接回车键)
#mysql -u root -p 或者#/usr/local/mysql/bin/mysql -uroot -p 使用第二个命令是没有配置环境变量 #export PATH=$PATH:/usr/local/mysql/bin
use mysql;
update user set authentication_string=password('123456') where user='root';
或者#set password=password("root");
flush privileges;
ALTER USER USER() IDENTIFIED BY '123456';
exit;
设置可以远程连接
mysql -u root -p use mysql; update user set host='%' where user = 'root'; flush privileges;
exit;