# 下载rpm包 wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm # 安装Mysql源 sudo rpm -Uvh mysql-community-release-el6-5.noarch.rpm # 查看mysql源,如果正常就能看到mysql6.5 yum repolist all | grep mysql
编辑下载源
1 2 3 4 5 6 7 8 9 10 11 12 13
# 编辑文件/etc/yum.repos.d/mysql-community.repo vi /etc/yum.repos.d/mysql-community.repo # 可看到如下mysql版本设置 # 通过配置 enable等于1或者0 来决定启用那个版本。 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
安装mysql
1 2 3 4 5 6 7
# 安装 yum install mysql-community-server # 启动mysql service mysqld start
修改root账户密码
1 2 3 4 5 6 7 8 9 10 11 12
# 连接登录mysql后,设置密码 set password for yourname@localhost = password('yourpassword'); # 退出后,使用新设置密码登录 #如果忘记root密码,则通过如下手段修改密码 mysqld_safe --skip-grant-tables& mysql -u root mysql mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root'; mysql> FLUSH PRIVILEGES;
设置mysql编码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# 连接登录mysql服务后,查看编码 SHOW VARIABLES LIKE 'character%'; # 设置编码为utf8 vi /etc/my.cnf # 在my.cnf文件的[mysqld]字段里面增加一行character-set-server=utf8 [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock character-set-server=utf8 # 修改完成后,重启mysql服务 service mysqld restart # 然后连接mysql后,再次查看编码 SHOW VARIABLES LIKE 'character%';
# 创建用户 CREATE USER 'yourname'@'%' IDENTIFIED BY 'yourpwd'; # 配置远程连接权限,并将新建的数据库权限赋权给当前用户 GRANT ALL PRIVILEGES ON dbname.* TO 'yourname'@'%' IDENTIFIED BY 'yourpwd' WITH GRANT OPTION; # 刷新权限 flush privileges; # 远程测试登录 mysql -h x.x.x.x -u yourname -p