MySQL安装
2023-02-23 15:34:10 5 举报
AI智能生成
MySQL安装
作者其他创作
大纲/内容
安装
创建MySQL用户,并修改密码
上传包,解压
创建可执行文件的软链接
ln -fs/usr/local/mysql/bin/* /usr/bin
创建MySQL所需的相关目录和文件
创建目录
mkdir -p /var/lib/mysql/data /var/lib/mysql/logs
创建错误日志文件
touch /var/lib/mysql/logs/r68.err
修改权限
chown -R mysql.mysql /var/lib/mysql
初始化MySQL
yum -y install numactl
mysqld --no-defaults --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql/data --innodb-data-file-path=ibdata1:2G:autoextend --innodb_undo_tablespaces=2 --lower-case-table-names=1
添加MySQL服务到系统服务中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --levels 24 mysqld off
chkconfig --add mysqld
chkconfig --levels 24 mysqld off
创建并修改MySQL配置文件
创建配置文件
vi /etc/my.cnf
将如下内容写入配置文件
[client]
user=root
password=123
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/var/lib/mysql/data
default_storage_engine=innodb
server_id=1111622
port=3306
skip_name_resolve=on
lower_case_table_names=1
log-bin=/var/lib/mysql/logs/r68-bin
log_bin_index=/var/lib/mysql/logs/r68.index
log_error=/var/lib/mysql/logs/r68.err
innodb_buffer_pool_size=1024M
user=root
password=123
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/var/lib/mysql/data
default_storage_engine=innodb
server_id=1111622
port=3306
skip_name_resolve=on
lower_case_table_names=1
log-bin=/var/lib/mysql/logs/r68-bin
log_bin_index=/var/lib/mysql/logs/r68.index
log_error=/var/lib/mysql/logs/r68.err
innodb_buffer_pool_size=1024M
启动MySQL
service mysqld start
service mysqld status
mysql -u root -p
报错解决
1.[root@yuzhiyi ~]# service mysqld start
Starting MySQL.2020-08-06T10:10:41.351651Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/var/lib/mysql/data/yuzhiyi.pid).
Starting MySQL.2020-08-06T10:10:41.351651Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/var/lib/mysql/data/yuzhiyi.pid).
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
/usr/local/mysql/support-files/mysql.server start
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
/usr/local/mysql/support-files/mysql.server start
2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
进入vim /etc/my.cnf
改一下路径socket=/tmp/mysql.sock
改一下路径socket=/tmp/mysql.sock
3.忘记密码
vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables
[mysqld]
skip-grant-tables
:wq! #保存退出
service mysqld restart #重启MySQL服务
改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED mysql_native_password BY '123456';(新版本)
改完之后把配置文件中那一行再删了
刷新一下 flush privileges;
[mysqld]
skip-grant-tables
:wq! #保存退出
service mysqld restart #重启MySQL服务
改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED mysql_native_password BY '123456';(新版本)
改完之后把配置文件中那一行再删了
刷新一下 flush privileges;
收藏
收藏
0 条评论
下一页