马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
linux环境安装
ubutun 系统查看是否安装libaio:dpkg -s libaio
ubutun 系统安装:sudo apt-get install libaio-dev
- sudo apt-get install libaio-dev
复制代码 第一种 :tar包安装
1、官网下载软件包:MySQL :: Download MySQL Community Server (Archived Versions)
2、将软件包放置/usr/local目次下,解压包
xz -d mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar
3、重命名软件包
4、新增用户名和组,授权目次
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql/
5、mysql下新建data目次
6、编辑/etc/my.cnf,chmod 640 /etc/my.cnf
[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data #data可设置/opt/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
#character config
character_set_server=utf8mb4
7、切换bin下初始化基础信息
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql --initialize
如果data 设置其他目次
./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/opt/mysql/data
--initialize:会生成随机密码
--intialize-insecure:初始化无密码
生成默认密码
8、添加mysql服务到系统并设置权限
9、添加系统服务并启动数据库,查看数据库状态
chkconfig --add mysql
启动服务
/etc/init.d/mysql start
service mysql start
10、将服务添加到启动PATH目次下
ln -s /usr/local/mysql/bin/mysql /usr/bin/
11、登录数据库,利用上面密码
mysql -u root -p
12、修改root密码
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
flush privileges;
重置mysql的root密码
1、停止mysql的历程和服务
killall -TERM mysqld”下令停止所有的mysqld历程
service mysql stop
2、进入bin目次,
./mysqld_safe --skip-grant-tables --user=mysql &
3、重新打开新终端,mysql -u root -p 免密进入,设置空格密码
use mysql;
update user set authentication_string = '' where user = 'root';
flush privileges;
4、杀掉启动 --skip-grant-tables的mysql历程
5、启动mysql服务
6、免密登录:mysql -u root -p
use mysql;
alter user 'root'@'localhost' identified with mysql_native_password by 'root';
错误:ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
解析:查root用,%表示授予root用户的host可以从任何主机的所有权限
localhost 标识只能允许当地访问
图中设置%,修改密码改成%
办理办法:
use mysql;
alter user 'root'@'%' identified with mysql_native_password by 'root';
flush privileges;
7、利用新密码正常登录:
错误日志
1、service mysql start 启动服务报错:
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
办理办法:
ubutun系统:apt-get install install libncurses*
centos系统:yum install libncurses*
2、service mysql start 启动服务报错:mysql :mysql is neither service nor target!? (suse12系统)
办理办法:
systemctl unmask my.service
service mysql start
3、10060 mysql_mysql错误:Can't connect to MySQL server (10060)
可能是你的帐号不允许从长途登陆,只能在localhost。登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
办理办法:
use mysql;
update user set host = '%' where user = 'root';
flush privileges;
select host, user from user;
4、毗连MySQL出现ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock
解析:找到mysql.sock文件的位置
一般mysql.sock会在/var/lib/mysql/mysql.sock 或者/var/lib/mysql.sock,一般写到MySQL设置文件 /etc/my.cnf里面,找到sock字段 修改为 /var/lib/mysql/mysql.sock 或/var/lib/mysql.sock
但是MySQL现实是会到/tmp 目次下找mysql.sock 文件。我们可以将var/lib/mysql/mysql.sock 软毗连到 /tmp/mysql.sock
办理办法:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
5、ERROR 1045 (28000): Access denied for user 'root'@'localhost':一般密码错误
6、Warning: World-writable config file '/etc/my.cnf' is ignored
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysqld.sock'
解析:/etc/my.cnf'权限全局可写,任何一个用户都可以写。mysql担心这种文件被其他用户恶意修改,以是忽略掉这个设置文件。导致无法启动
办理办法:chmod 640 /etc/my.cnf
参考:Linux-安装MySQL(具体教程)_linux安装mysql-CSDN博客
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |