赞
踩
家人们,今天分享两种MySQL的安装方法分别是yum安装和通用二进制安装:
1.可以手动配置yum源,baseurl指向国内镜像源地址,比如清华、中科大。
/etc/yum.repos.d/mysql.repo
[mysql]
name=mysql5.7
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
gpgcheck=0
2. 安装MySQL
yum install mysql-community-server
Starting the MySQL Server:
# systemctl start mysqld //当前启动
# systemctl enable mysqld //开机自启动
查询临时登录密码:
# awk '/temporary password/ {print $NF}' /var/log/mysqld.log
登录数据库:
# mysql -uroot -p
Enter password:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
# 修改密码
mysql> alter user root@localhost identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
# 密码要符合复杂性要求 RedHat@123
mysql> alter user root@localhost identified by 'RedHat@123';
Query OK, 0 rows affected (0.00 sec)
下载可以直接去www.mysql.com官网去下载
[root@node4 ~]# ll mysql-5.7.14-linux-glibc2.5-x86_64.tar
-rw-r--r-- 1 root root 672716800 Jul 5 14:15 mysql-5.7.14-linux-glibc2.5-x86_64.tar
2. 创建用户及组
# groupadd -r mysql
# useradd mysql -r -g mysql -c "MySQL Server" -s /bin/false
3.解压,软链接
# tar xf /usr/local/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
创建软链接:为了方便以后升级。
# ln -sv /usr/local/mysql-5.7.14-linux-glibc2.5-x86_64 /usr/local/mysql
‘/usr/local/mysql’ -> ‘/usr/local/mysql-5.7.14-linux-glibc2.5-x86_64’
4. 初始化
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
5. 提供配置文件和服务启动脚本
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
修改配置文件:vim /etc/my.cnf
[mysqld]
...
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
# 服务脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
添加系统服务,并设置开机自启动
# chkconfig --add mysqld
# chkconfig mysqld on
6. 启动mysql
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
# /usr/local/mysql/bin/mysql -uroot -p
# 密码在初始化里找
配置环境变量:
# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
加载使其生效并修改密码。
echo /bin/$PATH
sourse /etc/profile.d/mysql.sh
mysql -uroot -p登录后修改密码
# alter user root@localhost identified by '密码';
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。