Linux 通过源码包安装MySQL —— 觉悟版

以下步骤(都是精髓,哈哈): 

1、下载 ->

https://downloads.mysql.com/archives/community/

img

 

 wget  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

2、移动并创建用户授权解压的文件夹 ->

tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 

mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql

cd /usr/local/mysql/

mkdir data

#创建mysql用户并将mysql文件夹赋给mysql用户

groupadd mysql

useradd -g mysql mysql

 

chown -R mysql:mysql /usr/local/mysql/

chown -R mysql /usr/local/mysql/

chmod -R 755 /usr/local/mysql/

yum install  libaio-devel.x86_64

 

 

3、执行安装命令(获取临时密码) ->

bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

 提取临时密码:

2021-08-02T04:31:06.667033Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2021-08-02T04:31:07.442249Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-02T04:31:07.550975Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-02T04:31:07.628766Z 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: 74b825f8-f34a-11eb-89d0-000c29e6d702.
2021-08-02T04:31:07.640638Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-02T04:31:07.642172Z 1 [Note] A temporary password is generated for root@localhost: XbmEmHM*w7U6

注意:如果想重新生成,请删除根目录下的data目录下的全部文件,再重新初始化!!

 

报错:error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

ubuntu解决方法:apt-cache search libaio  &&  apt-get install libaio1

 

4、修改配置文件(/etc/my.conf) ->

vim /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
#skip-grant-tables

 

5、创建启动脚本并设置开机自启并立即启动(不然无法登录) ->

vim   /usr/lib/systemd/system/mysql.service       

[Unit] 
Description=MySQL Server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
LimitNOFILE = 65535
Restart=on-failure
RestartSec=10
RestartPreventExitStatus=1
PrivateTmp=false

 

chmod 777 /usr/lib/systemd/system/mysql.service     #设置权限

systemctl daemon-reload             #重新加载一下

systemctl enable mysql.service     #设置该服务为开机自启

systemctl  is-enabled  mysql.service   #查看是否能开机自启,enabled代表是,disabled则不行!

systemctl start mysql.service   #能否登录的关键点

6、将mysql加入环境变量(哪个位置都可以操作mysql) ->

设置环境变量

echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
source  /etc/profile

设置密码

mysql -uroot -p临时密码  #如果不行,可以先mysql -uroot -p回车再粘贴密码
              #error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file  ,ubuntu解决方法>>   centos: yum install libncurses* 
              #提示 '/var/run/mysqld/mysqld.sock' 这种错误。  解决方法>>

use mysql  
update user set authentication_string=password("xxxxxx") where user="root"; #设置密码,如果报错,请看下面的解决方面
# (5.7之前:mysql> UPDATE user SET Password = password ('XXXXX') WHERE User = 'root';)


use mysql    # 出现 ERROR 1820 (HY000)... ? 请看代码块下面
update user set host='%' where user = 'root'; #允许远程连接
exit;
systemctl restart mysql.service   #需要重新启动,不然远程连接失败

 

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

alter user 'root'@'localhost' identified by '你的密码';

SET PASSWORD = PASSWORD('你的新密码') ;  

8、退出并用新密码重新登录 END!

mysql -uroot -p你的新密码

https://blog.csdn.net/qq_36393978/article/details/110948418

posted @ 2021-06-09 18:01  小庄的blog  阅读(119)  评论(0编辑  收藏  举报