作者:乖乖雯莉_775 | 来源:互联网 | 2023-09-03 16:12
一.安装问题(源码安装)
参考博客:
1.https://blog.csdn.net/cmzsteven/article/details/78520829
2.https://www.cnblogs.com/chenkx6/p/13366638.html?utm_source=tuicool
服务器上本来就有数据库,按照1安装后无法连接数据库,于是按照2安装最后成功,但是我单独使用方法2解压,没有找到/xxx/mysql/bin目录无法继续安装下去。
方法一:
1.解压Mysql
tar -xvf openssl-1.0.2h.tar.gz
2.
cd mysql-8.0.21
mkdir configure
cd configure
3.使用cmake生成编译环境,检测依赖项。
cmake .. -DBUILD_CONFIG=mysql_release \
-DINSTALL_LAYOUT=STANDALONE \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DENABLE_DTRACE=OFF \
-DWITH_EMBEDDED_SERVER=OFF \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_ZLIB=system \
-DWITH_PAM=ON \
-DCMAKE_INSTALL_PREFIX=/home/qinbo/tool/mysql/ \ #自己定义
-DINSTALL_PLUGINDIR="/home/qinbo/tool/mysql/lib/plugin" \ #自己定义
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EDITLINE=bundled \
-DFEATURE_SET=community \
-DCOMPILATION_COMMENT="MySQL Server (GPL)" \
-DWITH_DEBUG=OFF \
-DWITH_BOOST=.. \ #boost所在路径
-DWITH_SSL=/home/qinbo/tool/openssl/ #openssl位置
过程中出现以下错误:
①
现象:一个和依赖项boost有关的报错。
原因:a.-DWITH_BOOST中配置的boost位置与boost实际位置不匹配。
b.boost版本不匹配,我此处需要安装的是boost1.72.0。(https://www.boost.org/users/history/version_1_72_0.html 源码下载地址)
②
原因:缺少依赖项ncurses,我此处安装的是ncurses-6.2。(http://ftp.gnu.org/gnu/ncurses/ 源码地址)
③
原因:缺少依赖项openssl,我此处安装的是openssl-1.0.2h。
④对cmake版本也是有要求的,不能过低。
⑤
/usr/lib/libstdc++.so.6: version `CXXABI_1.3.9' not found
有篇博客讲解的太透彻了:https://www.cnblogs.com/yinheyi/p/7248307.html
4.编译
make
5.安装 没报错一遍通过
make install
方法二:
没报错,一遍通过。
二.启动问题和连接问题
1.
现象:
[xxxxx@nfs-server61 bin]$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
原因:连接Mysql是通过socket配置文件进行连接,而Mysql找不到/tmp/mysql.sock文件。
解决办法:2个
①软链接:如果本机上没有其他数据库,可以通过软连接方式将寻找/tmp/mysql.sock文件的路径指向我们mysql安装目录下的/home/xxxxx/tool/mysql/mysql.sock文件。
ln -s /home/xxxxx/tool/mysql/mysql.sock /tmp/mysql.sock
②显示指定mysql.sock路径(我使用的方式)
mysql -u root -p -S /home/xxxxx/tool/mysql/mysql.sock
2. root用户
[xxxxx@nfs-server61 bin]$ mysql -u root -p -S /home/qinbo/tool/mysql/mysql.sock
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决:
①安装好Mysql8.0.21之后,无需输入密码,直接回车可以进入Mysql。
备用:
less error.log | grep root@localhost#获取初始密码,error.log在/xxx/mysql/error.log路径下。
②进入后立即设置密码,否则所有操作都会报以下错误。
ERROR 1820(HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password='qb123456';#设置root密码
3. 普通用户
现象:
[xxxxx@nfs-server61 bin]$ mysql -u qinbo -p -S /home/qinbo/tool/mysql/mysql.sock
Enter password:
ERROR 1045 (28000): Access denied for user 'qinbo'@'localhost' (using password: YES)
原因:没有该用户或该用户密码错误。
解决办法:
#1.查看现有用户
mysql> use mysql;
mysql> select User,Host from user;
#2.创建新用户
mysql> create user qinbo@localhost identified by 'qb123456';
#3.授予新用户所有权限
mysql> grant all privileges on mysql.* to qinbo@localhost;
#4.刷新权限表
mysql> flush privileges;
#5.显示用户权限
mysql> show grants for qinbo@localhost;
4.
现象:使用pymysql连接Mysql时遇到的问题。
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
原因:登陆用户‘root’时密码不正确或端口不正确(默认使用3306端口,如果Mysql配置文件my.cnf中的端口号不是3306,需要显示的指定端口号)
解决方法:
conn = pymysql.connect(host='localhost',user='root',password='qb123456',#注意用户名、密码、host一致port=33306,#非3306需要显示的指定database='corpus',#该数据库必须存在charset='utf8')