centos7.6 在线安装mysql
1、检查Linux是否安装了mariadb数据库,mariadb数据库是mysql的分支
执行命令:
yum list installed | grep mariadb
2、如果Linux中安装了mariadb数据库,先卸载掉,因为CentOS 7.6 内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb
执行命令:
yum -y remove mariadb-libs.x86_64
3、更新软件
yum update
4、下载和添加仓库
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update
5、安装MySql
yum install mysql-server
6、启动MySQL
systemctl start mysqld
7、配置MySql
运行如下脚本文件(然受一直y就行,最后一步会让你输入root密码)
mysql_secure_installation
8、修改字符集编码
vim /etc/my.cnf
========设置如下 在mysqld 和client下分别添加如下配置 client没有自己写======================
[mysqld] character_set_server = utf8 [client] default-character-set = utf8
9、重启MySQL服务
systemctl restart mysql.service
10、连接MySQL
mysql -uroot -p
11、查看编码
show variables like '%character%';
修改好以后是这样的
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
12、设置允许远程登陆
设置权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
应用设置
FLUSH PRIVILEGES;
重启mysql服务(应该不重启也行,保险起见还是重启吧)
systemctl restart mysql.service
13、开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload
centos7.2下解决用Mysql 使用navicate远程连接数据库出现1045 access denied for user 'root'@'localhost' using password yes
在mysql命令行中执行
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
若以上方法行不通则用:
use mysql;
UPDATE user SET Password=PASSWORD('123456') where USER='root';
flush privileges;