ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# MySQL 单机安装 [TOC] >说明: 本次只在bd00上安装了mysql 除了以下操作,其它操作均是在创建的bigdata用户操作 1.创建用户 2.关闭防火墙 3.卸载老软件 4.添加自启懂 ### 关闭防火墙 ``` systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running) ``` ### 检查是否安装NySQL,如果安装 卸载之 ``` rpm -qa |grep mysql yum remove mysql* ``` ### 检查是否安装MariaDB,如果安装 卸载之(重要) ``` rpm -qa |grep mariadb yum remove mariadb* ``` ## 安装 ### 添加用户 ``` useradd bigdata ``` >如果添加过了就不用了 ### 切换用户 ``` su - bigdata ``` ### 下载 ``` wget http://uni.mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz ``` ### 解压 ``` tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz ``` ### 修改文件夹名 ``` mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql ``` ### 进入mysql目录 ``` cd /home/bigdata/soft/mysql ``` ### 创建my.conf ``` vim /home/bigdata/soft/mysql/my.cnf ``` ``` [client] port=3306 socket=/home/bigdata/soft/mysql/mysql.sock [mysqld] basedir=/home/bigdata/soft/mysql datadir=/home/bigdata/soft/mysql/data socket=/home/bigdata/soft/mysql/mysql.sock user=bigdata pid-file=/home/bigdata/soft/mysql/data/mysql.pid #进程id [mysql] socket=/home/bigdata/soft/mysql/mysql.sock ``` ### 初始化 ``` ./bin/mysqld --defaults-file=/home/bigdata/soft/mysql/my.cnf \ --initialize \ --basedir=/home/bigdata/soft/mysql/ \ --datadir=/home/bigdata/soft/mysql/data/ \ --user=bigdata \ --socket=/home/bigdata/soft/mysql/mysql.sock ``` >实际效果如下,还有个密码? ``` [mysql@bd00 mysql]$ ./bin/mysqld --initialize --user=mysql \ > --basedir=/home/bigdata/soft/mysql/ \ > --datadir=/home/bigdata/soft/mysql/data/ 2019-05-24T14:50:38.189220Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2019-05-24T14:50:38.189310Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000) 2019-05-24T14:50:38.189429Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-05-24T14:50:38.508430Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-05-24T14:50:38.666223Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-05-24T14:50:38.776967Z 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: 4b918103-7e33-11e9-b47e-000c29034af1. 2019-05-24T14:50:38.778797Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-05-24T14:50:38.779456Z 1 [Note] A temporary password is generated for root@localhost: L#-ZlQ397_6m [mysql@bd00 mysql]$ ``` ### 复制mysql.server ``` cp /home/bigdata/soft/mysql/support-files/mysql.server /home/bigdata/soft/mysql/mysql.server ``` ### 修改mysqld ``` cd /home/bigdata/soft/mysql vim mysql.server ``` ``` basedir=/home/bigdata/soft/mysql datadir=/home/bigdata/soft/mysql/data ``` ### 添加环境变量 ``` vi /home/bigdata/.bash_profile ``` ``` export MYSQL_HOME=/home/bigdata/soft/mysql export PATH="$PATH:$MYSQL_HOME/bin" ``` ``` source /home/bigdata/.bash_profile ``` ## 运维 ### 启动 ``` /home/bigdata/soft/mysql/mysql.server start ``` ### 停止 ``` /home/bigdata/soft/mysql/mysql.server stop ``` ### 开机自启动 >本次是配合hadoop生态圈使用,比如HIVE使用,所以没有添加自启动 只需要把 `su - mysql -c "/home/bigdata/soft/mysql/mysql.server start"` 放到 `/etc/rc.d/rc.local` 即可 ### 初次登陆 ``` mysql -h127.0.0.1 -uroot -p ``` >输入密码后即可登录 ### 修改用户密码 ``` mysql> alter user 'root'@'localhost' identified by 'youpassword'; ``` 或者 ``` mysql> set password=password("youpassword"); ``` ### 允许远程连接 %代表任何ip ``` mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; ``` 刷新权限 ``` mysql>flush privileges; ``` 然后远程就能访问了 ## 参考 [https://www.jb51.net/article/150079.htm](https://www.jb51.net/article/150079.htm) [https://www.cnblogs.com/chinesern/p/9309853.html](https://www.cnblogs.com/chinesern/p/9309853.html)