当前位置:Gxlcms > 数据库问题 > MySQL二进制安装

MySQL二进制安装

时间:2021-07-01 10:21:17 帮助过:3人阅读

-P3308 【查看连接方式】 17:43:42 (none)> \s Connection: 127.0.0.1 via TCP/IP

2.5.3 登陆错误处理

1、Access denied

# 报错
mysql -p123123
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

# 检查用户名和密码(是root@localhost,还是root@127.0.0.1)登陆
# mysql登录时会自动检查my.cnf 中 [mysql] 和 [client]的配置,因为
# cat /etc/my.cnf |more
[client]
port                    = 3308
socket                  = /data/mysql20/data/mysql.sock

所以,mysql使用socket登陆,会报错登陆root@localhost这个用户错误

2、Character set ‘utf8mb4‘ is not a compiled character set

# mysql -proot 
mysql: Character set ‘utf8mb4‘ is not a compiled character set and is not specified in the ‘/usr/share/mysql/charsets/Index.xml‘ file

解决:
# yum list installed |grep mysql
mha4mysql-node.noarch              0.57-0.el6                        @/mha4mysql-node-0.57-0.el6.noarch
mysql.x86_64                        5.1.73-8.el6_8                    @base    #因为安装了这个mysql-devel时,安装了mysql5.1的客户端
mysql-devel.x86_64                  5.1.73-8.el6_8                    @base    
mysql-libs.x86_64                  5.1.73-8.el6_8                    @base    
zabbix-web-mysql.noarch            3.4.7-1.el6                        @zabbix  

# yum remove mysql.x86_64 

2.6 密码破解

通过选项skip-grant-tables来启动数据库:

  • --skip-grant-tables选项,此选项使服务器根本无需使用权限系统即可启动,使得所有人访问数据库不需要密码
  • 登陆后,通过set 或者alter 修改用户密码
  • 在shell中执行mysqladmin flush-privilegesmysqladmin reload命令,或登陆mysql后,flush privilege 让MySQL Serer重新加载授权表
# 启动
numactl --interleave=all  /data/mysql3308/bin/mysqld_safe --defualts-file=/etc/my.cnf  --skip-grant-tables & 
[1] 2435

# 登陆
mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.

#加载授权表,否则ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
18:06:28(none)>flush privileges;

#修改密码
set password for root@localhost = password(‘root‘);

2.7 MySQL进程检测

1、进程检测

# 检测命令
ps -ef |grep mysqld
ps aux |grep mysqld

# 进程信息
root    36133 21704  0 17:35 pts/1    00:00:00 /bin/sh /data/mysql3308/bin/mysqld_safe --defaults-file=/etc/my_frontweb_snap.cnf --ledir=/data/mysql3308/bin/
mysql    36978 36133  1 17:35 pts/1    00:00:06 /data/mysql3308/bin//mysqld --defaults-file=/etc/my_frontweb_snap.cnf --basedir=/data/mysql3308 --datadir=/data/mysql3308/data --plugin-dir=/data/mysql3308/lib/plugin --user=mysql --log-error=/data/mysql3308/data/error.log --open-files-limit=655350 --pid-file=/data/mysql3308/data/hadoop-jq-9-31.pid --socket=/data/mysql3308/data/mysql.sock --port=3308

# 关于进程号
可以从进程号中看出,root用户启动了mysqld_safe进程,mysql的父进程是mysqld_safe进程,也就是说,mysqld_safe拉起了mysql的mysqld程序

2、端口检测

# netstat检测
netstat -an |grep 3306

tcp        0      0 10.17.9.31:22261            10.17.1.110:3306            ESTABLISHED 
tcp        0      0 :::3306                    :::*                        LISTEN  


# lsof检测,需要安包
rpm -qf `which lsof`
lsof-4.82-4.el6.x86_64

lsof -i:3306 
COMMAND  PID  USER  FD  TYPE    DEVICE SIZE/OFF NODE NAME
mysqld  3229 mysql  16u  IPv6    15009      0t0  TCP *:mysql (LISTEN)

3、客户端检测

# mysql登录检测
能使用mysql登录指定mysqld服务,服务肯定是在运行的


# mysqladmin ping检测
mysqladmin -pmima  ping      
mysqld is alive

3、安装善后操作

3.1 mysql_secure_installation安全性改装

1、简介

  • 这和mysql一样,是一个客户端程序,程序在$basedir/bin/下
  • /data/mysql/bin/mysql_secure_installation
  • 作用是改进安装安全性,建议版本低于5.7的一定使用

2、如何使用

./mysql_secure_installation --help

# ./mysql_secure_installation -S /data/mysql3307/data/mysql.sock

Securing the MySQL server deployment.
Enter password for user root: 


mysql_secure_installation
Enter current password for root (enter for none):      # 密码为空,直接回车
Change the root password? [Y/n] Y                      #修改密码
Remove anonymous users? [Y/n] y                        #移除匿名用户.              ,5.7默认没有匿名用户
Disallow root login remotely? [Y/n] y                  #禁止root用户远程登陆root@’%’,5.7没有root@‘%‘用户
Remove test database and access to it? [Y/n] y          #移除test数据库              ,5.7无test数据库
Reload privilege tables now? [Y/n] y                    #刷新权限表

3.2 PATH 变量设置

1、优缺点

  • 优点
    • 设置path变量之后,对于mysql的很多程序都能直接使用
  • 缺点
    • 对于多实例的情况下,很容易造成生产的问题,比如:
    • 已有5.6mysql服务在运行,PATH变量设置的$5.6basedir/bin,想初始化或启动5.7的服务,必须使用5.7的绝对路径的命令,不然启动了一个5.6mysqld服务

2、如何设置

# 编辑文件
vim /etc/profile

#最后追加,以‘:‘分隔
PATH=$PATH:/data/mysql3308/bin

# 生效
. /etc/profile

3.3 开机自启

不在生产环境中使用开启自动启动mysqld服务。以为server一般不会重启,故障大都是硬件侧面,使用HA提供持续服务

3.3.1 创建系统service服务

利用$basedir/support-files/mysql.server 脚本创建/etc/init.d/mysqld 的快捷启动

#1、创建服务
cp $basedir/support-files/mysql.server /etc/init.d/mysqld        
修改脚本
chkconfig mysql on


#2、修改修改/etc/init.d/mysqld 脚本内容
#266行  
numactl --interleave=all /ssd_data/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf  &


-------------------------------------------------


#3、将mysqld服务开机启动
chkcofig mysqld on     #开机启动
chkconfig --list |grep mysqld    #查看启动项

3.3.2 启动命令加入rc.local

将mysqld_safe启动命令放到 /etc/rc.local中

cat /etc/rc.local
#追加内容:
numactl --interleave=all /ssd_data/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf  &

3.4 alias设置

创建alias别名命令,并写入系统配置文件

vim  /etc/profile
# 追加一下内容
alias mysql3306=‘mysql -uroot -p123123 -h127.0.0.1 -P3306‘
alias mysql3306shutdown=‘mysql -uroot -p123123 -h127.0.0.1 -P3306 shutdown‘
alias mysqlstartup=‘/etc/init.d/mysql start‘
alias vimmycnf=‘vim /export/servers/mysql/etc/my.cnf‘

MySQL二进制安装

标签:刷新   col   hang   内存   pool   end   sql   buffer   login   

人气教程排行