• 【CentOS】CentOS7.0 mysql与卸载


    mysql安装:

    在使用命令

    yum list mysql-server 安装mysql的时候,发现没有mysql的包。这时候,我们需要下载一个

    下载包

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

    下载完成,安装mysql-community-release-el7-5.noarch.rpm包

    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

    安装mysql

    sudo yum install mysql-server

    等待安装完成....

    然后选择Y

    安装完成后,mysql没有密码需要重置密码才行。

    mysql -u root

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    解决办法:

    1、mysql服务未正常运行:

    由于mysql的socket文件是由mysqld服务启动时创建的,如果mysqld服务未正常启动,socket文件自然也不会被创建,当然会找不到socket文件了。对于判断mysql服务是否启动,我们可以使用下面命令:

    复制代码
    # 1、 端口是否打开
    [root@aiezu.com ~]# lsof -i:3306
    COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    mysqld  12207 mysql   14u  IPv4  52350      0t0  TCP *:mysql (LISTEN)
     
    # 2、mysqld服务是否正在运行
    [root@aiezu.com ~]# service mysqld status
    mysqld (pid  4717) is running...
    复制代码

    2、socket文件路径在配置文件中设置不完整:

    这一般是由于我们修改了mysql配置“/etc/my.cnf”引起的。比如我们修改了配置文件中“[mysql]”选项下的“socket”参数,而未指定“[client]”、“[mysql]”选项的“socket”参数,导致mysql使用默认的socket文件位置去寻找socket文件,从而导致未找到socket文件而引发此错误。

    1、mysql服务未正常运行:

    如果是服务未启动,我们运行“service mysqld start”启动服务即可。如果服务启动不了,就去查看mysql服务日志,寻找原因并解决再启动

    复制代码
    [root@aiezu.com ~]# service mysqld start
    Starting mysqld:                                           [  OK  ]
    [root@aiezu.com ~]# lsof -i:3306
    COMMAND   PID  USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
    mysqld  14109 mysql   10u  IPv4 247183583      0t0  TCP *:mysql (LISTEN)
    [root@aiezu.com ~]# service mysqld status
    mysqld (pid  14109) is running...
    复制代码

    2、完善mysql配置文件:

    如果确认mysql服务正常运行,还提示文章标题的此错误,那就是“/etc/my.cnf”配置文件的问题了。解决办法是修改“/etc/my.cnf”配置文件,在配置文件中添加“[client]”选项和“[mysql]”选项,并使用这两个选项下的“socket”参数值,与“[mysqld]”选项下的“socket”参数值,指向的socket文件路径完全一致。如下:

    复制代码
    [mysqld]
    datadir=/storage/db/mysql
    socket=/storage/db/mysql/mysql.sock
    ...省略n行...
     
    [client]
    default-character-set=utf8
    socket=/storage/db/mysql/mysql.sock
     
    [mysql]
    default-character-set=utf8
    socket=/storage/db/mysql/mysql.sock
    复制代码

    原文地址:http://www.aiezu.com/db/mysql_cant_connect_through_socket.html

    如果仍解决不了问题,可尝试下面的操作:

    Check below things to fix the issue
    
    Check the permission of mysql data dir using below command
    
    # ls -ld /var/lib/mysql/
    
    Check the permission of databases inside mysql data dir using below command
    
    # ls -lh /var/lib/mysql/
    
    Check the listening network tcp ports using below command
    
    # netstat -ntlp
    
    Check the mysql log files for any error using below command.
    
    # cat /var/log/mysql/mysqld.log
    
    Try to start mysql using below command
    
    # mysqld_safe --defaults-file=/etc/my.cf

    修改密码:

    # mysql -uroot -p
    Enter password: 【输入原来的密码】(如果安装完mysql第一次设置root密码,则直接回车)
    mysql>use mysql;
    mysql> update user set password=password("123456") where user='root';
    mysql> flush privileges;
    mysql> exit;

    配置mysql允许远程连接的方法

    默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。

    一、修改/etc/mysql/my.conf
    找到bind-address = 127.0.0.1这一行
    改为bind-address = 0.0.0.0即可

    二、为需要远程登录的用户赋予权限

    1、新建用户远程连接mysql数据库

    mysql>use mysql;
    
    mysql>create user  luffy IDENTIFIED by '123456';   //identified by 会将纯文本密码加密作为散列值存储
    mysql
    >grant select,delete,update,insert on *.* to 'luffy'@'%' identified by '123456' ; mysql>flush privileges;

    允许任何ip地址(%表示允许任何ip地址)的电脑用luffy帐户和密码(123456)来访问这个mysql server。

    2、支持root用户允许远程连接mysql数据库

    mysql>grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
    mysql>flush privileges;

    三、查看系统用户

    PS.如果远程依然连不上可以参考:

    https://jingyan.baidu.com/article/380abd0a3aef431d90192c33.html

    mysql安装二 

    1、下载mysql安装包 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

    2、先cd /usr/local下: 然后解压 tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

    解压后为了方便后面操作可把解压后文件名修改为mysql:

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

    3、然后去到support-files目录下复制my.cnf 到 /etc/my.cnf (mysqld启动时自动读取)cp my-default.cnf /etc/my.cnf

    最新版本已经没有my-default.cnf这个文件了

    my.cnf

    [client]
    loose_default-character-set = utf8 
    socket = /usr/local/mysql/data/mysql.sock
    [mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 #server_id = 1 socket = /usr/local/mysql/data/mysql.sock expire_logs_days = 7 innodb_file_per_table innodb_buffer_pool_size = 2G innodb_thread_concurrency = 24 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 32M innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 wait_timeout = 60 interactive_timeout = 7200 skip-name-resolve character-set-server = utf8 back_log = 50 max_connections = 3000 max_connect_errors = 32 max_allowed_packet = 32M binlog_cache_size = 8M max_heap_table_size = 512M tmp_table_size = 64M key_buffer_size = 16M read_buffer_size = 2M read_rnd_buffer_size = 8M bulk_insert_buffer_size = 64M sort_buffer_size = 4M join_buffer_size = 2M thread_cache_size = 64 thread_stack = 192K query_cache_type = 1 query_cache_size = 256M query_cache_limit = 2M ft_min_word_len = 2 default_storage_engine = INNODB #default_table_type = INNODB transaction_isolation = REPEATABLE-READ lower_case_table_names = 1 #log_slow_queries slow_query_log long_query_time = 2 log-short-format myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 [mysqldump] quick max_allowed_packet = 32M routines single-transaction hex-blob skip-comments complete-insert skip-disable-keys skip-add-locks skip-lock-tables [isamchk] key_buffer = 512M sort_buffer_size = 512M read_buffer = 8M write_buffer = 8M [myisamchk] key_buffer = 512M sort_buffer_size = 512M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    4、复制mysql.server 到/etc/init.d/ 目录下【目的想实现开机自动执行效果】

    执行命令:cp mysql.server /etc/init.d/mysql(mysql是服务名)

    5、修改 /etc/init.d/mysql 参数vi /etc/init.d/mysql给与2个目录位置basedir=/usr/local/mysqldatadir=/usr/local/mysql/data

    6、出于安全便利,创建一个操作数据库的专门用户

    1)、groupadd mysql #建立一个mysql的组

    2)、useradd -r -g mysql mysql #建立mysql用户,并且把用户放到mysql组

    3)、passwd mysql #给mysql用户设置一个密码

    4)、给目录/usr/local/mysql 更改拥有者 chown -R mysql:mysql /usr/local/mysql/

    初始化 mysql 的数据库

    首先去到mysql的bin目录

    1.初始化./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

    生成出一个data目录,代表数据库已经初始化成功并且mysql的root用户生成一个临时密码:xxxxx(最好先记录这个临时密码)

    碰到以下问题就是这操作1,没有执行导致

    Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 

    2.给数据库加密./mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

    3.启动mysql(为了不让进程卡主,可在启动mysql的命令后加上&;代表此进程在后台运行)./mysqld_safe --user=mysql &;

    4.检查ps -ef|grep mysql

    发现有以上进程便代表启动成功。

    第五步:进入客户端

    1.登录 ./mysql -uroot -p回车后输入之前的临时密码2.修改密码set password=password('新密码');

    mysql: command not found

    解决:# ln -s /usr/local/mysql/bin/mysql /usr/bin

    mysql卸载:

    一、使用以下命令查看当前安装mysql情况,查找以前是否装有mysql

    rpm -qa|grep -i mysql

    可以看到如下图的所示:

    2、停止mysql服务、删除之前安装的mysql

    删除命令:rpm -e –nodeps 包名

    rpm -ev MySQL-client-5.5.25a-1.rhel5 
    rpm -ev MySQL-server-5.5.25a-1.rhel5

    如果提示依赖包错误,则使用以下命令尝试

    rpm -ev MySQL-client-5.5.25a-1.rhel5 --nodeps

    如果提示错误:error: %preun(xxxxxx) scriptlet failed, exit status 1

    则用以下命令尝试:

    rpm -e --noscripts MySQL-client-5.5.25a-1.rhel5

    3、查找之前老版本mysql的目录、并且删除老版本mysql的文件和库

    find / -name mysql

    查找结果如下:

    find / -name mysql 
     
    /var/lib/mysql
    /var/lib/mysql/mysql
    /usr/lib64/mysql

    删除对应的mysql目录

    rm -rf /var/lib/mysql
    rm -rf /var/lib/mysql
    rm -rf /usr/lib64/mysql

    具体的步骤如图:查找目录并删除

    注意:卸载后/etc/my.cnf不会删除,需要进行手工删除

    rm -rf /etc/my.cnf

    4、再次查找机器是否安装mysql

    rpm -qa|grep -i mysql

    参考地址:https://www.cnblogs.com/wolf-sun/p/5655439.html

    参考地址:https://www.cnblogs.com/nicknailo/articles/8563456.html

    参考地址:https://www.aliyun.com/jiaocheng/133867.html?spm=5176.100033.1.15.22996b04YjkV5D

  • 相关阅读:
    关键性点位
    【转】Chrome——F12 谷歌开发者工具详解
    LPR-贷款市场报价利率
    盘口-挂单
    看盘
    复盘
    2020超星尔雅后台挂课工具(完全免费)
    Codeup 问题 D: String Subtraction (20)
    维瓦尔第协奏曲《四季》赏析 (Antonio Vavildi 《The Four Seasons》)
    算法4-5:求子串位置的定位函数
  • 原文地址:https://www.cnblogs.com/mqxs/p/8630036.html
Copyright © 2020-2023  润新知