一.将repos源放在/etc/yum.repos.d目录下
(1.)安装源
下载源:https://dev.mysql.com/downloads/repo/yum/
rpm -ivh mysql57-community-release-el6-n.noarch.rpm安装完成后会出现两个.repo:mysql-community.repo mysql-community-source.repo
(2.)查看可用源
yum repolist all | grep mysql
(3.)修改源
vi /etc/yum.repos.d/mysql-community.repo
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
enabled=0表示disable,
1表示enbale
如果安装5.6版本的按如上修改,其他版本设置为disable
(4.)查看enbale的mysql源
yum repolist enbaled|grep mysql
二.安装数据库
(1.)yum安装
yum install mysql-community-server
(2.)启动数据库
修改配置文件/etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character_set_server = utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set = utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
对应EL7平台,可以用如下命名启动:
systemctl start mysqld.service
2.查看mysql状态
service mysqld status
对于EL7,可以用如下查看
systemctl status mysqld.service
这里就安装完成了
3.登入数据库
第一次登陆直接回车(不需要输入密码)
mysql -uroot -p
第一次可能登录成功,关掉mysql服务 service mysqld stop
用安全模式启动服务 mysqld_safe --skip-grant-tables &
或者:
在mysql5.7之前的版本首次登陆是无需密码的,但是5.7起会生成一个初始化密码/root/.mysql_secert cat /root/.mysql_secert...
然后直接进入update mysql.user set password=PASSWORD('123456') where User=root and host='localhost';
flush privileges;
退出重新启动mysql,密码登入
show databases
use mysql
修改root用户的密码
update user set password=password('passwd') where user='root'
或者
ALTER USER 'root'@'localhost' IDENTIFIED BY 'passwd';
刷新权限
flush privilege
4.mysql开机自启动设置
chkconfig mysqld on
或者
systemctl enable mysqld.service