美文网首页Linux
【服务与运维】2.0 centos7安装mysql——源码:cm

【服务与运维】2.0 centos7安装mysql——源码:cm

作者: bobokaka | 来源:发表于2021-04-25 19:10 被阅读0次

    https://typecodes.com/web/centos7compilemysql.html
    https://typecodes.com/web/solvemysqlcompileerror.html
    以下内容凡是执行过程中找不到某个文件的,手动新建该文件即可。直到不报错为止。
    删除mariadb

    rpm -qa | grep mariadb
    
    rpm -e --nodeps mariadb-connector-c-config-3.0.7-1.el8.noarch
    
    rpm -e --nodeps mariadb-connector-c-3.0.7-1.el8.x86_64
    
    
    cd /data/company/company_software/
    

    xshell传输文件的指令

    zy -y
    

    1.0 rpm安装方式(弃用):

    rpm -ivh MySQL_*
    

    2.0 cmake方式安装mysql(企业级使用)
    下载cmake

    [root@www company_software]# wget https://github.com/Kitware/CMake/releases/download/v3.17.1/cmake-3.17.1.tar.gz
    [root@www company_software]# wget https://github.com/Kitware/CMake/releases/download/v3.17.2/cmake-3.17.2.tar.gz
    [root@www company_software]# wget https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1.tar.gz
    

    安装cmake

    [root@www company_software]# ll
    
    image.png
    [root@www company_software]# tar -zxvf cmake-3.20.1.tar.gz 
    [root@www company_software]# cd cmake-3.20.1/
    [root@www cmake-3.20.1]# ./configure
    
    image.png
    [root@www cmake-3.20.1]# gmake
    
    image.png
    [root@www cmake-3.20.1]# gmake install
    
    image.png

    安装依赖包

    #######Ncurses:提供功能键定义(快捷键),屏幕绘制以及基于文本终端的图形互动功能的动态库。
    #######bison:GNU分析器生成器tat
    #######Boost库:一个开源可移植的C++库,是C++标准化进程的开发引擎之一
    yum install -y git gcc gcc-c++ ncurses-devel bison
    ######下载gmock:google的c++mock框架,从mysql 5.6开始支持
    yum install gmock
    [root@isso mysql-5.7.29]# yum install openssl*
    

    下载安装boost1.59.0(这里mysql5.7版本要求boost版本为1.59.0)

    wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
    

    解压(未使用)

    [root@isso ttwis_software]# tar xf boost_1_59_0.tar.gz 
    [root@isso ttwis_software]# cd boost_1_59_0/
    [root@isso boost_1_59_0]# ./bootstrap.sh --prefix=/usr/local/boost
    
    image.png
    [root@isso boost_1_59_0]# ./b2  stage threading=multi link=shared  install --prefix=/usr/local/boost
    
    image.png

    设置组合用户

    groupadd mysql
    useradd -g mysql -m  mysql
    

    下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/,换阿里云源

    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    

    运行 yum makecache 生成缓存

    解压mysql二进制包

    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30.tar.gz
    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.34.tar.gz
    
    [root@www company_software]# tar zxf mysql-5.7.30.tar.gz 
    [root@www company_software]# tar zxf mysql-5.7.34.tar.gz 
    
      cd mysql-5.7.30
    cd mysql-5.7.34/
    

    直接把解压后的boost放入mysql解压目录下

    cp -r ../boost_1_59_0 ./boost
    
    
    image.png

    命令安装

    cmake . -DCMAKE_INSTALL_PREFIX=/data/company/company_program/mysql-5.7.34 \
    -DMYSQL_DATADIR=/data/company/company_program/mysql-5.7.34/data \
    -DMYSQL_UNIX_ADDR=/data/company/company_program/mysql-5.7.34/tmp/mysql.sock \
    -DSYSCONFDIR=/etc \
    -DMYSQL_USER=mysql \
    -DMYSQL_TCP_PORT=3306 \
    -DDEFAULT_CHARSET=utf8mb4 \
    -DDEFAULT_COLLATION=utf8mb4_general_ci \
    -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
    -DENABLED_LOCAL_INFILE=ON \
    -DENABLE_DOWNLOADS=1 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
    -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_FAST_MUTEXES=1 \
    -DWITH_ZLIB=bundled \
    -DWITH_BOOST=./boost \
    -DWITH_SSL:STRING=system \
    -DENABLED_LOCAL_INFILE=1 \
    -DWITH_READLINE=1 \
    -DWITH_EMBEDDED_SERVER=1 \
    -DMYSQL_MAINTAINER_MODE=0 \
    -DWITH_DEBUG=0
    
    

    -DDOWNLOAD_BOOST=1
    -DWITH_BOOST=./boost \

    DYMSQL_UNIX_ADDR sock路径
    DDEFAULT_CHARSET默认字符集
    DDEFAULT_COLLATION默认的校对规则
    DEXTRA_CHARSETS支持的额外的字符集
    DENABLED_LOCAL_INFILE打开LOCAL_INFILE功能
    -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 支持各种引擎

    看到如下画面表示mysql编译成功:


    image.png
    make && make install
    

    安装完成界面:


    图片.png

    使用命令查看编译成功后的mysql安装目录

    [root@www mysql-5.7.34]# ls -lrt /data/company/company_program/mysql-5.7.34/
    total 296
    -rw-r--r--  1 root root    587 Dec 18 20:59 README-test
    -rw-r--r--  1 root root    587 Dec 18 20:59 README
    -rw-r--r--  1 root root 276202 Dec 18 20:59 LICENSE
    drwxr-xr-x  2 root root      6 Apr 23 18:38 logs
    drwxr-xr-x  2 root root      6 Apr 24 17:20 data
    drwxr-xr-x  2 root root      6 Apr 24 17:23 tmp
    drwxr-xr-x  2 root root     55 Apr 25 12:27 docs
    drwxr-xr-x  3 root root   4096 Apr 25 12:27 include
    drwxr-xr-x  4 root root     30 Apr 25 12:27 man
    drwxr-xr-x  4 root root    192 Apr 25 12:27 lib
    drwxr-xr-x  2 root root   4096 Apr 25 12:27 bin
    drwxr-xr-x 10 root root   4096 Apr 25 12:28 mysql-test
    drwxr-xr-x 28 root root   4096 Apr 25 12:28 share
    drwxr-xr-x  2 root root     90 Apr 25 12:28 support-files
    [root@www mysql-5.7.34]# ls -lrt /data/company/company_program/mysql-5.7.34/lib/
    total 547356
    -rwxr-xr-x 1 root root   6833256 Apr 25 11:16 libmysqlclient.so.20.3.16
    -rw-r--r-- 1 root root  13705968 Apr 25 11:16 libmysqlclient.a
    -rw-r--r-- 1 root root     41246 Apr 25 11:48 libmysqlservices.a
    -rw-r--r-- 1 root root 539894432 Apr 25 12:26 libmysqld.a
    lrwxrwxrwx 1 root root        25 Apr 25 12:27 libmysqlclient.so.20 -> libmysqlclient.so.20.3.16
    lrwxrwxrwx 1 root root        20 Apr 25 12:27 libmysqlclient.so -> libmysqlclient.so.20
    drwxr-xr-x 3 root root      4096 Apr 25 12:27 plugin
    drwxr-xr-x 2 root root        28 Apr 25 12:27 pkgconfig
    [root@isso mysql-5.7.29]# 
    

    如果lib目录下面没有生成如图所示的.so动态库文件和.a静态库文件,那么说明安装不成功(即使成功了也可能会导致php进程无法找到mysql的相关库文件)。


    image.png

    设置MySQL的配置文件my.cnf
    编译生成的my.cnf文件在/etc/my.cnf.rpmsave中

    [client]
    #password       = your_password
    port            = 3306
    socket          = /data/company/company_program//mysql-5.7.34/tmp/mysql.sock
    default-character-set=utf8mb4
    [mysqld]
    user = mysql
    port            = 3306
    server-id = 1
    lower_case_table_names=1
    socket          = /data/company/company_program//mysql-5.7.34/tmp/mysql.sock
    basedir = /data/company/company_program//mysql-5.7.34
    datadir = /data/company/company_program//mysql-5.7.34/data
    default_storage_engine = InnoDB
    character-set-server = utf8mb4
    #default-character-set=utf8mb4
    
    log-error = /data/company/company_program//mysql-5.7.34/logs/error.log
    pid-file = /data/company/company_program//mysql-5.7.34/logs/mysql.pid
    general_log = 1
    performance_schema_max_table_instances = 400
    table_definition_cache = 400
    skip-external-locking
    skip-name-resolve
    back_log = 300
    
    max_connections = 1000
    max_connect_errors = 6000
    open_files_limit = 65535
    table_open_cache = 256
    key_buffer_size = 64M
    max_allowed_packet = 200G
    binlog_cache_size = 1M
    max_heap_table_size = 8M
    tmp_table_size = 64M
    
    sort_buffer_size = 8M
    join_buffer_size = 28M
    key_buffer_size = 512M
    
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    thread_cache_size = 32
    query_cache_type = 1
    query_cache_size = 32M
    query_cache_limit = 2M
    
    ft_min_word_len = 4
    
    log_bin = mysql-bin
    binlog_format = mixed
    expire_logs_days = 30
    
    performance_schema = 0
    explicit_defaults_for_timestamp
    
    net_buffer_length = 4K
    
    myisam_sort_buffer_size = 16M
    myisam_repair_threads = 1
    
    interactive_timeout = 28800
    wait_timeout = 28800
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    sql_mode="NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES"
    #sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    explicit_defaults_for_timestamp = true
    
    
    log-bin=mysql-bin
    binlog_format=mixed
    
    expire_logs_days = 10
    slow_query_log=1
    slow-query-log-file=/data/company/company_program//mysql-5.7.34/logs/mysql-slow.log
    long_query_time=3
    #log_queries_not_using_indexes=on
    
    
    innodb_data_home_dir = /data/company/company_program//mysql-5.7.34/data
    innodb_data_file_path = ibdata1:10M:autoextend
    innodb_log_group_home_dir = /data/company/company_program//mysql-5.7.34/data
    innodb_buffer_pool_size = 256M
    innodb_log_file_size = 128M
    innodb_log_buffer_size = 32M
    innodb_flush_log_at_trx_commit = 1
    innodb_lock_wait_timeout = 50
    innodb_max_dirty_pages_pct = 90
    innodb_read_io_threads = 2
    innodb_write_io_threads = 2
    
    [mysqldump]
    #user=root
    #password="3a853e98fe66636e"
    quick
    max_allowed_packet = 500M
    
    [mysql]
    no-auto-rehash
    
    [myisamchk]
    key_buffer_size = 512M
    sort_buffer_size = 8M
    read_buffer = 4M
    write_buffer = 4M
    
    [mysqlhotcopy]
    interactive-timeout
    
    

    把my.cnf放到/etc目录下。

    添加mysql的环境变量
    将MySQL编译生成的bin目录添加到当前Linux系统的环境变量中

     echo -e '\n\nexport PATH=/data/company/company_program/mysql-5.7.34/bin:$PATH\n' >> /etc/profile && source /etc/profile
    

    或者 vim /etc/profile

    export JAVA_HOME=/data/company/company_program/java8
    export JRE_HOME=/data/company/company_program/java8/jre
    export NGINX_HOME=/usr/local/nginx/sbin
    export MYSQL_HOME=/data/company/company_program/mysql-5.7.34
    
    export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib:$NGINX_HOME:$MYSQL_HOME/lib
    export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$NGINX_HOME:$MYSQL_HOME/bin
    

    配置生效

    source /etc/profile
    

    相关安全配置

    [root@isso etc]# chown -R mysql:mysql /data/company/company_program/mysql-5.7.34
    

    初始化MySQL自身的数据库

    #####参数user表示用户,basedir表示mysql的安装路径,datadir表示数据库文件存放路径
    mysqld --initialize-insecure --user=mysql --basedir=/data/company/company_program/mysql-5.7.34 --datadir=/data/company/company_program/mysql-5.7.34/data
    
    cd ../../company_program/mysql-5.7.34/bin
    
    ./mysqld_safe  --user=mysql --basedir=/data/company/company_program/mysql-5.7.34  --datadir=data/company/company_program/mysql-5.7.34/data &
    
    [root@www mysql-5.7.34]#  mysqld --initialize-insecure --user=mysql --basedir=/data/company/company_program/mysql-5.7.34 --datadir=/data/company/company_program/mysql-5.7.34/data
     100
     100
    2021-04-25T09:27:28.165768Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2021-04-25T09:27:28.867366Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    mysqld: File '/data/company/company_program/mysql-5.7.34/logs/mysql-slow.log' not found (Errcode: 2 - No such file or directory)
    2021-04-25T09:27:28.873974Z 0 [ERROR] Could not use /data/company/company_program/mysql-5.7.34/logs/mysql-slow.log for logging (error 2 - No such file or directory). Turning logging off for the server process. To turn it on again: fix the cause, then either restart the query logging by using "SET GLOBAL SLOW_QUERY_LOG=ON" or restart the MySQL server.
    2021-04-25T09:27:28.876803Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 744609e8-a5a8-11eb-aa43-00163e156267.
    2021-04-25T09:27:28.877797Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2021-04-25T09:27:29.289950Z 0 [Warning] CA certificate ca.pem is self signed.
    2021-04-25T09:27:29.407002Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    [root@www mysql-5.7.34]#
    
    image.png

    权限调整

    [root@isso bin]# chmod -R 775 /data/company/company_program/mysql-5.7.34/logs/
    [root@isso bin]# ll /data/company/company_program/mysql-5.7.34/logs/
    total 8
    -rwxrwxr-x 1 mysql mysql 1079 Apr 25 14:18 error.log
    -rwxrwxr-x 1 mysql mysql  538 Apr 25 14:18 mysql-slow.log
    [root@isso bin]#  cp /data/company/company_program/mysql-5.7.34/support-files/mysql.server  /etc/init.d/mysqld
    
    图片.png

    增加可执行权限

     chmod +x /etc/init.d/mysqld
    

    添加到sysV服务

    chkconfig --add mysqld
    
    chkconfig mysqld on
    

    启动mysql服务

    mysqld_safe --user=mysql --datadir=/data/company/company_program/mysql-5.7.34/data --log-error=/data/company/company_program/mysql-5.7.34/logs/error.log &
    

    启动

    service mysqld start
    
    图片.png

    然后使用下面这命令ps -ef | grep mysql和netstat -tunpl | grep 3306查看MySQL服务进程和端口监听情况:


    图片.png

    初始化MySQL数据库的root用户密码:

     mysql_secure_installation
    
    [root@isso bin]#  mysql_secure_installation
    mysql_secure_installation: [ERROR] unknown option '--no-auto-rehash'
    
    Securing the MySQL server deployment.
    保护MySQL服务器部署。
    Connecting to MySQL using a blank password.
    使用空密码连接到MySQL。
    
    VALIDATE PASSWORD PLUGIN can be used to test passwords
    and improve security. It checks the strength of password
    and allows the users to set only those passwords which are
    secure enough. Would you like to setup VALIDATE PASSWORD plugin?
    验证密码插件可用于测试密码
    提高安全性。它检查密码的强度
    并允许用户只设置
    足够安全。是否要设置验证密码插件?
    Press y|Y for Yes, any other key for No: y
    按y | y表示是,按任何其他键表示否:y
    There are three levels of password validation policy:
    There are three levels of password validation policy:
    LOW    Length >= 8【只需要长度大于或等于8】
    MEDIUM Length >= 8, numeric, mixed case, and special characters 【还需要包含数字、大小写和类似于@#%等特殊字符】
    STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
    【还需要包含字典文件】
    Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
    Please set the password for root here.1
    安全级别选中等
    New password: 
    
    Re-enter new password: 
    
    Estimated strength of the password: 100 
    Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
    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.
    是否继续使用提供的密码?(按y | y表示是,按任何其他键表示否):y
    默认情况下,MySQL安装有一个匿名用户,
    允许任何人登录MySQL而不必
    为他们创建的用户帐户。这只是为了
    测试,使安装更顺利。
    你应该在投入生产前把它们去掉
    环境。
    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    Success.
    
    
    Normally, root should only be allowed to connect from
    'localhost'. This ensures that someone cannot guess at
    the root password from the network.
    通常,根目录只允许从
    “本地主机”。这保证了有人不能猜到
    来自网络的根密码。
    不允许远程根登录?(按y | y表示是,按任何其他键表示否):n
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 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.
    默认情况下,MySQL附带一个名为“test”的数据库
    任何人都可以进入。这也只是为了测试,
    在投入生产之前应该移除
    环境。
    删除测试数据库并访问它?(按y | y表示是,按任何其他键表示否):y
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
     - Dropping test database...
    Success.
    
     - Removing privileges on test database...
    Success.
    
    Reloading the privilege tables will ensure that all changes
    made so far will take effect immediately.
    重新加载特权表将确保所有更改
    到目前为止所做的将立即生效。
    现在重新加载特权表?(按y | y表示是,按任何其他键表示否):y
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    Success.
    
    All done! 
    

    密码:自己想设置的root用户的登录密码。

    将MySQL数据库的动态链接库共享至系统链接库

    一般MySQL数据库还会被类似于PHP等服务调用,所以我们需要将MySQL编译后的lib库文件添加至当前Linux主机链接库/etc/ld.so.conf.d/下,这样MySQL服务就可以被其它服务调用了。

    [root@www bin]# echo "/data/company/company_program/mysql-5.7.34/lib" > /etc/ld.so.conf.d/mysql.conf
    

    [使生效]

    [root@isso bin]# ldconfig
    

    [查看效果]

    [root@www bin]# ldconfig -v |grep mysql 
    ldconfig: Can't stat /libx32: No such file or directory
    ldconfig: Path `/usr/lib' given more than once
    ldconfig: Path `/usr/lib64' given more than once
    ldconfig: Can't stat /usr/libx32: No such file or directory
    /data/company/company_program/mysql-5.7.34/lib:
        libmysqlclient.so.20 -> libmysqlclient.so.20.3.21
    [root@www bin]# 
    
    image.png

    登录mysql

    /data/ttwis/ttwis_program/mysql-5.7.29/lib:
        libmysqlclient.so.20 -> libmysqlclient.so.20.3.16
    [root@isso bin]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.7.29-log Source distribution
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> 
    
    

    创建其它MySQL数据库用户(未使用)
    使用MySQL数据库root管理员用户登录MySQL数据库后,可以管理数据库和其他用户了。这里演示创建一个名为typecodes的MySQL用户(密码为@typecodes2014.com)和一个名为typecodes的数据库。

    [root@typecodes mysql]# mysql -uroot -p密码
    
    ######登录成功后,创建typecodes数据库,并设置字符集和字符校
    mysql> CREATE DATABASE `typecodes` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected (0.00 sec)
    
    ######创建名为typecodes用户,并让它拥有typecodes数据库所有的权限
    mysql> grant all privileges on typecodes.* to typecodes@localhost identified by '@typecodes2014.com';
    Query OK, 0 rows affected, 1 warning (0.01 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit;            [创建完毕,root用户退出]
    

    授权可以远程访问
    https://www.cnblogs.com/xiaofu007/p/10513845.html

    //grant all privileges on *.* to root@'%'identified by 'passwd';
    GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "自己设置好的root密码";
    flush privileges;
    

    GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY "Ttwis@8852";
    设置可以远程访问

    阿里云或者腾讯云记得在“本实例安全组”中开放必要的端口,比如mysql的3306。

    查看端口

    netstat -nupl (UDP类型的端口)
    netstat -ntpl (TCP类型的端口)
    

    重启mysql

    service mysqld restart
    
    

    service mysqld start

    设置开机自启动
    创建用于启动MySQL的配置文件

    [root@localhost ~]# touch /usr/lib/systemd/system/mysqld.service
    [root@localhost ~]# cd /usr/lib/systemd/system
    

    vim mysqld.service

    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    
    [Install]
    WantedBy=multi-user.target
    
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/data/company/company_program/mysql-5.7.34/bin/mysqld --defaults-file=/etc/my.cnf
    LimitNOFILE = 5000
    

    修改mysqld.service所属用户组,保持和配置文件一致

    chown -R mysql:mysql mysqld.service

    启动MySQL

    systemctl start mysqld

    设置自启动

    systemctl enable mysqld

    重启

    reboot

    查看MySQL是否自启动

    ps -ef|grep mysql

    修改密码:

    1.关闭mysql服务

     net stop mysql 
    

    2.找到mysql安装路径找到 my.ini 打开在 [mysqld] 下添加 skip-grant-tables 跳过密码校验 3.登陆mysql mysql -uroot -p密码随便输入

    4.进入MySQL 改密码

    mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';    ///123456自己的新密码
    

    *特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了

    5.记得把my.ini中的 skip-grant-tables 去掉否则谁都可以登陆我们的数据库了</pre>


    image
    image

    相关文章

      网友评论

        本文标题:【服务与运维】2.0 centos7安装mysql——源码:cm

        本文链接:https://www.haomeiwen.com/subject/kpgxwhtx.html