(编辑:jimmy 日期: 2024/12/27 浏览:2)
1.下载mysql
1.1下载地址
https://downloads.mysql.com/archives/community/
1.2版本选择
2.管理组及目录权限
2.1解压mysql
tar -zxf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz上传目录/home/tools
2.2重命名
mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql-5.7.29
2.3移动指定目录
mv mysql-5.7.29 /usr/local/
2.4添加用户组与用户
groupadd mysql
useradd -r -g mysql mysql
2.5修改目录权限
chown -R mysql:mysql /usr/local/mysql-5.7.29/
3.安装mysql
3.1配置mysql服务
cp /usr/local/mysql-5.7.29/support-files/mysql.server /etc/init.d/mysql
3.2修改mysql服务
vi /etc/init.d/mysql
3.3 修改配置文件my.cnf
vi /etc/my.cnf
拷贝内容如下,按需调整参数
[client] port = 33066 default-character-set=utf8 [mysqld] # 一般配置选项 basedir = /usr/local/mysql-5.7.29 datadir = /usr/local/mysql-5.7.29/data port = 33066 character-set-server=utf8 default_storage_engine = InnoDB sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZEO, NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
3.4初始化mysql
/usr/local/mysql-5.7.29/bin/mysqld
--initialize--user=mysql
--basedir=/usr/local/mysql-5.7.29
--datadir=/usr/local/mysql-5.7.29/data
成功如下,注意密码
3.5启动服务
service mysql start
4.登录与远程设置 4.1登录mysql
./mysql -u root p 记住注册密码
4.2修改root登录密码
set password=password('新密码');
4.3开启远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码'; flush privileges;
5.环境变量与开机启动配置
5.1设置环境变量
vi /etc/profile
添加如下内容
# mysql environment export MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile更新系统变量
5.2开机启动
chkconfig --add mysql mysql服务到自启服务
chkconfig mysql on 设置自启
chkconfig --list查看服务列表
总结