linux 安装mysql5.5.6

第一次安装,过程中遇到了不少问题,这里做了记录。
1、下载安装包
2 、移动到指定目录并解压

   tar -zvxf  mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz  

解压后 修改解压目录为 mysql

       mv mysql-5.5.62-linux-glibc2.12-x86_64  mysql 

3、 添加系统mysql组和mysql用户:
执行命令:groupadd mysql和useradd -r -g mysql mysql
4、创建mysql数据目录,新目录不存在则创建.
  数据库数据默认目录datadir=/var/lib/mysql,可通过vim /etc/my.cnf 查看
在 mysql主目录下 mkdir ./data

5、 修改数据权限 chown -R mysql:mysql ./
6、初始化数据库

scripts/mysql_install_db --user=mysql --basedir=/usr/apps/mysql/mysql --datadir=/usr/apps/mysql/mysql/data  

7、添加到启动服务 cp support-files/mysql.server /etc/init.d/mysql
8、服务启动 service mysql start 提示错误如下:

  Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/shizhan01.pid).

遇到这种问题 注释掉 my.cnf 中的无用目录
添加basedir 修改 datadir 注释 socket ,如下图:
在这里插入图片描述
按照安装完成的提示 执行bin/mysql_secure_sinstallation 完成密码配置
在这里插入图片描述

   [root@shizhan01 mysql]# bin/mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
 ... skipping.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] n
 ... skipping.
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
 ... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n
 ... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

问题:
本地 mysql -uroot -p 连接mysql 成功后 ,show databases 只有两个 performance_schema || test
同时在其他客户端连接 提示 :
错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server

百度得知 需要切换到mysql 数据库中 去执行相应操作才能解决。
执行 use mysql时报错
提示:ERROR 1044 (42000): Access denied for user ‘’@‘localhost’ to database ‘mysql’。

百度解决原因及办法如下
在网上找了半天,终于发现是因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的’’@'localhost’可以看出来,解决办法如下:
方法一:
1.关闭mysql

 # service mysqld stop

2.屏蔽权限

   # mysqld_safe --skip-grant-table

屏幕出现: Starting demo from …
3.新开起一个终端输入

  # mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD(‘newpassword’) where USER=‘root’;
mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> \q

方法二:
1.关闭mysql

  # service mysqld stop

2.屏蔽权限

   # mysqld_safe --skip-grant-table

屏幕出现: Starting demo from …
3.新开起一个终端输入

 # mysql -u root mysql

mysql> delete from user where USER=’’;
mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> \q

但是在 执行 # mysqld_safe --skip-grant-table 时 报错 提示 不知道 --skip-grant-table 这个配置项
百度找到了另外一种方式 再 /etc/my.cnf 中增加 skip-grant-table (完成设置后注释掉)然后重启mysql服务
在这里插入图片描述

按照上述两种方法执行 完成后注释掉 my.cnf 中的 配置 重启服务执行如下sql
新建一个用户 mysql 拥有所有权限
grant all privileges on . to mysql identified by ‘mysql’;
然后用 mysql 用户 再客户端登录 成功!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
你可以按照以下步骤安装和配置 MySQL 5.5.6: 1. 下载MySQL 5.5.6安装文件:你可以在MySQL官方网站上下载适用于你的操作系统的安装文件。选择正确的版本(32位或64位)以及适当的操作系统。 2. 安装MySQL:双击安装文件,按照提示进行安装。在安装过程中,你可以选择自定义安装选项,以便选择安装目录和其他设置。 3. 配置MySQL安装完成后,进入MySQL安装目录,在该目录下找到my.ini或my.cnf文件(具体名称取决于你的操作系统),用文本编辑器打开它。 4. 修改配置文件:在配置文件中,你可以修改MySQL的各种配置选项。以下是一些常见的配置选项: - datadir:指定MySQL数据库文件的存储路径。 - port:指定MySQL服务器监听的端口号。 - character-set-server:指定MySQL服务器使用的字符集。 - max_connections:指定允许的最大连接数。 - innodb_buffer_pool_size:指定InnoDB存储引擎使用的内存池大小。 根据你的需求,修改这些配置选项。保存并关闭配置文件。 5. 启动MySQL服务:根据你的操作系统,使用相应的命令启动MySQL服务。例如,在Windows上,你可以在命令提示符下运行`net start mysql`命令。在Linux上,你可以运行`service mysql start`命令。 6. 测试连接:打开MySQL的命令行客户端,并使用root用户登录。如果成功登录,表示MySQL安装和配置成功了。 这些是安装和配置MySQL 5.5.6的基本步骤。请注意,在实际操作中可能会有一些差异,具体取决于你的操作系统和个人需求。建议查阅MySQL官方文档或其他可靠资源,以获取更详细和准确的安装和配置信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catch that elf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值