Ubuntu mysql

Ubuntu 环境:

mysql 的版本:

 问题1 : 安装 mysql 之后, 终端输入任意的密码 ,竟然都能登录 。在本机用同一个账户 navicat 却死活登录不上,也查看了 mysql 数据库 user 表的数据, 用户和密码输入都是正确的, 不知道配置文件哪里有问题, 找了一上午,太无语了,只好

愤怒的删了 root 用户, 然后连终端也登不上了, 然后问题2 解决了,问题1 也解决了。

 问题2 : 不小心删除了 root 用户

停止运行 mysl 服务器 : service mysql stop

编辑 mysql 的配置文件 : /etc/mysql/conf.d/mysql.cnf, 添加内容 :

1 [mysqld]
2 skip-grant-tables

启动 mysql 服务器 : service mysql start

进入 mysql 的交互环境 :

mysql > use mysql;

mysql > insert into user(host,user,authentication_string,ssl_cipher,x509_issuer,x509_subject) values('%','root',password(''),"","","");   # 此处 host 和 密码 简单设置只是为了测试目的的使用,不能在生产环境使用

mysql > update user set select_priv='y', insert_priv='y',update_priv='y', Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y' where user='root';
插入 root 用户之后 , 记得删除 /etc/mysql/conf.d/mysql.cnf 添加的内容,重启。

 

相关命令:

安装 redis : apt-get install redis

安装 mysql : apt-get install mysql-server mysql-client

安装 mysql 扩展 : apt-get install php-mysql

安装 : apt-get install apache2

启动,重启,停止 : /etc/init.d/apache2  start | restart | stop

默认发布目录 :  /var/www/html

查看 mysql 配置文件的读取的路径 : mysql --verbose --help | grep my.cnf

mysql 交互环境下的命令:

查看当前登录的用户 : mysql > select user();

授权用户 : mysql >  grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;

     mysql > flush privileges;

原文地址:https://www.cnblogs.com/jingjingdidunhe/p/7465402.html