https://dev.mysql.com/downloads/mysql/ 网址
https://www.cnblogs.com/xiaxiaoxu/p/9978976.html 安装链接
检查是否安装过MySQL: rpm -qa|grep -i mysql
需要先安装:yum install ‘perl(Data::Dumper)‘
可以忽略这步: 安装后备份 修改名称,防止干扰:mv /etc/my.cnf /etc/my.cnf.bak
安装:rpm -ivh ****.rpm --force --nodeps (需要加’--force --nodeps‘ 否则会报错)
启动mysql出错 service mysql start
需要执行命令:/usr/bin/mysql_install_db --user=mysql 链接:https://www.cnblogs.com/weibanggang/p/11230528.html
关闭 : service mysql stop
设置新密码:/usr/bin/mysqladmin -u root password 123456
5.6版本mysql 拷贝配置文件 :找到初始配置文件 cd usr/share/mysql/my-default.cnf
拷贝到:cp my-default.cnf /etc/my.cnf
查看 mysql 使用的字符编码集 show variables like ‘%char%‘;
编辑时出现序号:set nu
/etc/my.cnf 修改内容:
[client]port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld]
character_set_server = utf8
character_set_client = utf8
collation-server = utf8_general_ci
[mysql]
no-auto-rehash
default-character-set=utf8
修改配置文件后,字符编码集仍不生效,则有可能mysql加载配置文件后,后面的配置项会覆盖前面的,
查看MySQL加载配置文件价顺序:mysqld --help --verbose|grep -A1 -B1 cnf
配置数据库远程连接:
进入mysql数据库:use mysql;
查看user表中的数据:select Host, User,Password from user;
修改user表中的Host:update user set Host=‘%‘ where User=‘root‘;
最后刷新一下:flush privileges;
linux服务器安装Mysql后,只能看到information_schema/test这两个库,无法修改密码
1.关闭Mysql:执行 service mysql stop
2.用安全模式启动Mysql,如果是自己通过tar包手动安装的Mysql,mysqld_safe命令在“${mysql}/bin”下
mysqld_safe --skip-grant-tables
3. 复制当前链接,再打开一个ssh连接,登录到mysql数据库
直接用命令mysql,就进入了数据了,不需要密码
修改mysql.user表
use mysql;
delete from user;
INSERT INTO user (Host,User, Password,Select_priv, Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv, File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,
Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,
Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,Event_priv,Trigger_priv,
Create_tablespace_priv,ssl_type, ssl_cipher,x509_issuer, x509_subject,max_questions,max_updates,
max_connections,max_user_connections, plugin,authentication_string) VALUES
(‘%‘,‘root‘,‘ ‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘ ‘,‘ ‘,‘ ‘,‘ ‘,0,0,0,0,‘ ‘,‘ ‘),
(‘127.0.0.1‘,‘root‘,‘ ‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘ ‘,‘ ‘, ‘ ‘,‘ ‘,0,0,
0,0,‘ ‘,‘ ‘), (‘::1‘,‘root‘,‘ ‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘ ‘,‘ ‘,‘ ‘,‘ ‘,0,0,0,0,‘ ‘,‘ ‘),
(‘localhost‘,‘ ‘,‘ ‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘,‘ ‘,‘ ‘,‘ ‘,‘ ‘,0,0,0,0,
‘ ‘,‘ ‘);
4.重启mysql: service mysql restart
启动后登录mysql数据库,可以正常看到所有的数据库了。