微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

centos下mysql数据库安装、创建库和表,备份还原

一、创建运行MysqL数据库的系统用户、组。

[root@beyond ~]# useradd -M -s /sbin/nologin MysqL

解压并释放源代码

[root@beyond mnt]# tar zxvf MysqL-5.0.56.tar.gz -C /usr/src/

要是配置编译不了,就配置yum源

安装下面的软件;

[root@beyond MysqL-5.0.56]# yum install *vim*

[root@beyond MysqL-5.0.56]# yum install -y *termcaP*

配置编译;

[root@beyond MysqL-5.0.56]# ./configure --prefix=/usr/local/apache2

Remember to check the platform specific part of the reference manual for

hints about installing MysqL on your platform. Also have a look at the

files in the Docs directory.

Thank you for choosing MysqL!

编译并安装;

[root@beyond MysqL-5.0.56]# make && make install

2.建立配置文件

[root@beyond MysqL-5.0.56]# cp support-files/my-medium.cnf /etc/my.cnf

初始化数据库

[root@beyond MysqL-5.0.56]# /usr/local/MysqL/bin/MysqL_install_db --user=MysqL

修改相关目录的所有权,以便MysqL用户可以读写数据库

[root@beyond MysqL-5.0.56]# chown -R root.MysqL /usr/local/MysqL/

[root@beyond MysqL-5.0.56]# chown -R MysqL /usr/local/MysqL/

调整lib库路径:

[root@beyond MysqL-5.0.56]# echo "/usr/local/MysqL/lib/MysqL" >> /etc/ld.so.conf

刷新库文件搜索路径,使修改生效

[root@beyond MysqL-5.0.56]# ldconfig

MysqL启动控制;

[root@beyond MysqL-5.0.56]# /usr/local/MysqL/bin/MysqLd_safe --user=MysqL &

[root@beyond MysqL-5.0.56]# netstat -ntpl | grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 23437/MysqLd

MysqLd添加为系统服务;

[root@beyond MysqL-5.0.56]# cp support-files/MysqL.server /etc/init.d/MysqLd

[root@beyond MysqL-5.0.56]# chmod +x /etc/init.d/MysqLd

[root@beyond MysqL-5.0.56]# chkconfig --add MysqLd

[root@beyond MysqL-5.0.56]# chkconfig MysqLd on

设置MysqL程序的执行路径;

[root@beyond MysqL-5.0.56]# export PATH=$PATH:/usr/local/MysqL/bin/

[root@beyond MysqL-5.0.56]# echo "PATH=$PATH:/usr/local/MysqL/bin" >> /etc/profile

数据库的基本管理,登录退出MysqL环境

[root@beyond ~]# MysqL -u root

Welcome to the MysqL monitor. Commands end with ; or \g.

Your MysqL connection id is 1

Server version: 5.0.56-log Source distribution 退出;exit

MysqL>

设置root用户MysqL数据库密码

[root@beyond ~]# MysqLadmin -u root password "123.com"

[root@beyond ~]# MysqL -u root -p

Enter password:

数据库结构,

//查询数据库的命令:

MysqL> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| @R_24_4045@ion_schema |

| MysqL |

| test |

+--------------------+

3 rows in set (0.00 sec)

查询数据库中的数据表;

MysqL> USE MysqL;

Database changed

MysqL> SHOW TABLES;

+---------------------------+

| Tables_in_MysqL |

+---------------------------+

| columns_priv |

| db |

| func |

| help_category |

| help_keyword |

| help_relation |

| help_topic |

| host |

| proc |

| procs_priv |

| tables_priv |

| time_zone |

| time_zone_leap_second |

| time_zone_name |

| time_zone_transition |

| time_zone_transition_type |

| user |

+---------------------------+

17 rows in set (0.00 sec)

数据库的创建和删除

MysqL> CREATE DATABASE beyond;

Query OK,1 row affected (0.00 sec)

MysqL> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| @R_24_4045@ion_schema |

| beyond |

| MysqL |

| test |

+--------------------+

4 rows in set (0.00 sec)

删除数据库

MysqL> DROP DATABASE taotao;

Query OK,0 rows affected (0.00 sec)

创建和删除数据表;

MysqL> CREATE TABLE songs (songs_name CHAR(30) NOT NULL,songs_passwd CHAR(20) NOT NULL DEFAULT '123.com',PRIMARY KEY (songs_name));

Query OK,0 rows affected (0.02 sec)

插入新的数据记录;

MysqL> INSERT INTO auth.users(user_name,user_passwd) VALUES('huangjiajv',ENCRYPT('123456'));

Query OK,1 row affected (0.01 sec)

MysqL> INSERT INTO auth.users(user_name,user_passwd) VALUES('huangguanzhong',ENCRYPT('com.123'));

Query OK,1 row affected (0.00 sec)

修改数据表信息;

MysqL> UPDATE auth.users SET user_passwd=ENCRYPT('123.com') WHERE user_name='taotao';

Query OK,0 rows affected (0.00 sec)

Rows matched: 0 Changed: 0 Warnings: 0

数据库的备份和恢复;

[root@www ~]# MysqLdump -u root -p auth > MysqL-auth.sql

Enter password:

[root@www ~]# ll MysqL-auth.sql

-rw-r--r-- 1 root root 1863 Dec 30 01:01 MysqL-auth.sql //备份数据库

删除数据库auth;

MysqL> USE MysqL;

Database changed

MysqL> DROP DATABASE auth;

Query OK,1 row affected (0.01 sec)

查看一下是否删除

MysqL> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| @R_24_4045@ion_schema |

| beyond |

| MysqL |

| test |

+--------------------+

4 rows in set (0.00 sec)

[root@www ~]# MysqL -u root -p auth < MysqL-auth.sql

Enter password:

[root@www ~]# MysqLdump -u root -p beyond > /usr/src/MysqL-beyond.sql

Enter password:

[root@www ~]# ll /usr/src/MysqL-beyond.sql

-rw-r--r-- 1 root root 1775 Dec 30 02:00 /usr/src/MysqL-beyond.sql

[root@www ~]# MysqL -u root -p beyond < /usr/src/MysqL-beyond.sql

Enter password:

[root@www ~]#

备份某个数据库中的某个表;

[root@www ~]# MysqLdump -u root -p MysqL host user > MysqL.host-user.sql

Enter password:

[root@www ~]#

刚装了MysqL

sudo apt-get install MysqL

安装成功了,安装最后要求输入了密码,也输入了,OK

MysqL -uroot -p

输入设置的密码

竟然报错了!

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YSE)

问朋友,他说初始密码是空的,可我命名设置了密码的阿。

密码留空

还是错误

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

于是重改密码

#sudo /etc/init.d/MysqL stop

# MysqLd_safe --user=MysqL --skip-grant-tables --skip-networking &

# MysqL -u root MysqL

MysqL> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

MysqL> FLUSH PRIVILEGES;

MysqL> quit

# /etc/init.d/MysqL restart

# MysqL -u root -p

Enter password:

MysqL>

搞定!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。