安装mysql 5.7
- 首先去mysql官网下载想要的版本的rpm包,我这里使用mysql5.7版本。==因为是在centos下安装,记得只能下载rpm包==
- 将下载的rpm包放到centos7系统相应的文件夹中,推荐使用==winscp==软件来实现window系统与linux系统之间文件传递。
- 进入centos系统里存放mysql的rpm文件的文件夹,使用命令
yum localinstall + rpm包名
安装。
image
3.1 ==仅仅执行rpm还不算真的安装mysql,必须再使用yum install mysql-community-server
来安装myqsl==
- 安装成功后可以使用命令
yum repolist all|grep mysql
来查看安装结果以及mysql的版本信息
image
==可以看出只有5.7版本是启动状态(因为下载的就是5.7版本的rpm包)==,如果想要激活其他版本的mysql,可参考以下操作:
yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql56-community-dmr
或者采用修改配置文件的方式 /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
==enable的值为0表示禁用,1表示启用==
查看本机安装的mysql的版本号
[root@centos64-02 yum.repos.d]# yum repolist enabled|grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 36
mysql-tools-community/x86_64 MySQL Tools Community 47
mysql57-community/x86_64 MySQL 5.7 Community Server 207
查看mysql相关文件的位置
[root@centos64-02 yum.repos.d]# whereis mysql
mysql: /usr/lib64/mysql /usr/local/mysql /usr/share/mysql
[root@centos64-02 yum.repos.d]#
启动mysql服务
[root@centos64-02 yum.repos.d] # systemctl start mysqld
获取默认随机生成的密码,并重置
[root@centos64-02 etc]# cat /var/log/mysqld.log|grep password
2017-07-19T01:04:45.248243Z 1 [Note] A temporary password is generated for root@localhost: g4e26lrMM!gy
2017-07-19T01:05:20.585839Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T01:11:52.375751Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T01:11:55.131770Z 5 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T01:21:43.056325Z 6 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T01:22:21.155491Z 7 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T01:23:18.120100Z 8 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T01:23:22.515380Z 9 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-07-19T01:34:18.970916Z 10 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T01:36:47.484062Z 11 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-07-19T01:39:16.574308Z 0 [Note] Shutting down plugin 'validate_password'
2017-07-19T01:39:18.303952Z 0 [Note] Shutting down plugin 'sha256_password'
2017-07-19T01:39:18.303954Z 0 [Note] Shutting down plugin 'mysql_native_password'
2017-07-19T02:25:22.827081Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T02:25:39.030177Z 4 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-07-19T02:26:08.313919Z 5 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T02:26:15.181663Z 6 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-07-19T02:26:17.754514Z 7 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-07-19T02:26:35.221528Z 8 [Note] Access denied for user 'root'@'localhost' (using password: YES)
[root@centos64-02 etc]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
==5.7以后官方对密码设置要求变严,建议使用字母大小写+特殊符号+足够位数==
登录mysql
mysql -u root -p
远程访问配置
创建一个管理员账户,用户名为 admin 密码为 自定义(需要满足要求),并配置所有权限
mysql> create user 'admin'@'%' identified by 'admin123456MYSQL!';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL ON *.* TO 'admin'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
修改字符编码
首先查看当前mysql的字符集
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
可以看出默认字符集为latin1 ,这对中文字符不太支持。
修改 /etc/my.cnf
文件,添加字符集的设置。
网友评论