一、进入终端,开始执行,一步一步来,等完上一步再搞下一步:
1、wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2、sudo rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
3、sudo yum install mysql-community-server
就三步安装完毕。
二、修改密码.
修改mysql 的root密码(忘记或不知道密码时也可以这样修改)
【1】修改为无密码登录
vi /etc/my.cnf
在最后添加
# skip password
skip-grant-tables=1
保存
重启mysql服务
systemctl restart mysqld
【2】修改密码
mysql -u root 使用命令行连接mysql数据库
当使用update user set passsword=password("123456") where user="root";修改root密码时会提示如下错误:
ERROR 1054 (42S22): Unknown column 'passsword' in 'field list'
这是因为在MySQL 5.7 password字段已从mysql.user表中删除,新的字段名是“authenticalion_string”.
可使用use mysql; desc user;查看如下:
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | NO | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.00 sec)
上面表中标红的就是新的密码字段。使用上面的字段就可以重置密码 :
update user set authentication_string=password('123456') where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
执行:flush privileges;刷新一下。
按入如上两部操作完后退出再使用mysql -u root -p和新密码就可以登录了
启动和结束命令:
1、启动命令: sudo systemctl start mysqld.service
2、停止命令: sudo systemctl stop mysqld.service
3、查看状态:sudo systemctl status mysqld.service
置root远程连接数据库【1】在mysql中设置权限
mysql -u root -p
输入数据库密码(上一步设置的)
use mysql;
grant all privileges on *.* to ‘root’@’%’ identified by ‘123@WSXqaz’;
flush privileges;
exit;
grant all privileges表示赋于所有权限
on *.*表示mysql中的所有数据对象
to ‘root’@’%’表示给root赋权,%允许root从任意ip连接
identified by ‘123@WSXqaz’
表示root从远程登录时使用的密码
要比root从本机登录时使用的密码更复杂
从本机登录时还可以使用之前的密码
flush privileges;刷新权限
【2】在防火墙中开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
查看开启的端口
firewall-cmd --zone=public --list-ports
使用Navicat从远程连接数据库
日常管理时,都使用Navicat或者phpmyadmin连接到数据库上进行相应的操作,而不使用mysql命令