MySQL安装
2018-07-20 本文已影响14人
GeekAmI
- 安装MySQL
rpm -qa|grep mysql-server //检查是否已经安装了mysql
# 如果没有,需下载各种rpm包
wget mysql-community-common-5.7.22-1.el6.x86_64.rpm网址
wget mysql-community-libs-5.7.22-1.el6.x86_64.rpm网址
wget mysql-community-client-5.7.22-1.el6.x86_64.rpm网址
wget mysql-community-server-5.7.22-1.el6.x86_64.rpm网址
# 依次yum上面的包
sudo rpm -ivf mysql-community-common-5.7.22-1.el6.x86_64.rpm
...
sudo rpm -ivf mysql-community-server-5.7.22-1.el6.x86_64.rpm
- 配置字符集
# 增加字符集配置
vim /etc/my.cnf
character-set-server=utf8mb4 #建议用utf8mb4
default-character-set=utf8 #亲测不适用mysql5.7
image.png
- 启动MySQL
# chkconfig mysqld on //设置开机启动
# chkconfig --list mysqld
# service mysqld restart
# ps -ef|grep mysql
- 设置MySQL密码
# 如果初始密码忘记
vim /var/log/mysqld.log #查找随机密码
mysql> select user, host, password from mysql.user
mysql> set password for root@localhost = password('123456')
mysql> set password for root@iz2zegf3gifygjjvqqlsipz = password('123456');
mysql> set password for root@127.0.0.1 = password('123456');
mysql> delete from mysql.user where user=''; //删除匿名用户
- 建库
# mysql> insert into mysql.user(user,host,password) values("myuser", "localhost",password( "123456"));
# mysql> flush privileges;
# CREATE DATABASE IF NOT EXISTS `mydb` DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
# mysql> grant all privileges on mydb.* to myuser@localhost identified by '123456';
# 给用户newuser设置库youdb的访问权限,密码为newuserpass
grant all privileges on youdb.* to newuser@'%' identified by 'newuserpass';
- 建表
cd /developer/
mysql -uroot -p
mysql> use youdb;
mysql> source /developer/db.sql
-
友情提醒:数据库升级或重装前,数据一定要备份、备份、备份
-
问题参考:
1)编码问题:
https://www.daguanren.cc/post/mysqlutf8mb4.html
2)远程连接问题:
https://blog.csdn.net/sun614345456/article/details/53672150
https://blog.csdn.net/u010758410/article/details/76381632
3)CentOS安装5.7问题:
下载:https://dev.mysql.com/downloads/file/?id=476896
https://blog.csdn.net/weixin_38287709/article/details/80404648
https://www.cnblogs.com/bigbrotherer/p/7241845.html
4)启动问题:Fatal error: mysql.user table is damaged
答案:https://www.jianshu.com/p/c6cabef4e9e5
5)授权用户问题:
https://www.cnblogs.com/xyzdw/archive/2011/08/11/2135227.html